โ05-27-2025 06:21 AM
I am following the examples outlined here: https://learn.microsoft.com/en-us/azure/databricks/machine-learning/manage-model-lifecycle/ to register a model to unity catalog.
I keep getting this error : BlockingIOError: [Errno 11] Resource temporarily unavailable:
Any ideas how to resolve this?
Many thanks!
โ05-27-2025 11:08 AM
This is a common issue when running MLflow in Databricks environments.
The "Resource temporarily unavailable" error typically indicates a file system or process locking issue.
Here are several solutions to try:
Immediate Fixes
1. Set MLflow tracking URI explicitly:
import mlflow
import os
# Set the tracking URI to use Databricks workspace
mlflow.set_tracking_uri("databricks")
# Or try setting it to the workspace URL
# mlflow.set_tracking_uri("databricks://your-workspace-url")
2. Configure MLflow registry URI:
# For Unity Catalog
mlflow.set_registry_uri("databricks-uc")
# Then proceed with your model registration
model_uri = f"runs:/{run_id}/model"
mlflow.register_model(model_uri, "principal_analysts.nco.iris_model")
3. Add retry logic:
import time
import mlflow
from mlflow.exceptions import MlflowException
def register_model_with_retry(model_uri, model_name, max_retries=3):
for attempt in range(max_retries):
try:
return mlflow.register_model(model_uri, model_name)
except Exception as e:
if "Resource temporarily unavailable" in str(e) and attempt < max_retries - 1:
print(f"Attempt {attempt + 1} failed, retrying in 5 seconds...")
time.sleep(5)
else:
raise e
# Use it like this:
model_uri = f"runs:/{run_id}/model"
register_model_with_retry(model_uri, "principal_analysts.nco.iris_model")
โ05-28-2025 01:28 AM
โ05-28-2025 10:31 AM
Looking at your error, the issue is that run_id is not defined when you try to use it.
The problem is in how you're getting the run ID from the MLflow run object.
Here are the correct ways to fix this:
Solution 1: Fix the run_id extraction
The issue is in your code where you have:
autolog_run = mlflow.last_active_run()
model_uri = "runs:{}/model".format(autolog_run.info.run_id) # This line has the error
The correct way:
import mlflow
from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier
# Set tracking URI
mlflow.set_tracking_uri("databricks")
mlflow.set_registry_uri("databricks-uc")
# Start MLflow run explicitly
with mlflow.start_run() as run:
# Train model
X, y = datasets.load_iris(return_X_y=True, as_frame=True)
clf = RandomForestClassifier(max_depth=7)
clf.fit(X, y)
# Log model
mlflow.sklearn.log_model(clf, "model")
# Get run_id from the active run
run_id = run.info.run_id
# Register model
model_uri = f"runs:/{run_id}/model"
mlflow.register_model(model_uri, "principal_analysts.nco.iris_model")
Solution 2: Use mlflow.active_run() instead
import mlflow
from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier
mlflow.set_tracking_uri("databricks")
mlflow.set_registry_uri("databricks-uc")
with mlflow.start_run():
# Train model
X, y = datasets.load_iris(return_X_y=True, as_frame=True)
clf = RandomForestClassifier(max_depth=7)
clf.fit(X, y)
# Log model
mlflow.sklearn.log_model(clf, "model")
# Get current active run
current_run = mlflow.active_run()
run_id = current_run.info.run_id
# Register model
model_uri = f"runs:/{run_id}/model"
mlflow.register_model(model_uri, "principal_analysts.nco.iris_model")
The Key Fix
The main issue in your original code was this line:
run_id = run.info.run_id # 'run' was not defined in this scope
They properly capture the run_id within the correct scope where the run object is available.
The error you're seeing suggests that either:
The run variable is not in scope when you try to access run.info.run_id
The run object is None or doesn't have the expected structure
Try Solution 1 first - it's the most straightforward and should resolve your issue.
โ05-29-2025 01:30 AM
โ05-30-2025 09:03 AM
This persistent "Resource temporarily unavailable" error in Databricks with
Unity Catalog is often related to workspace permissions or configuration issues.
Let's try several troubleshooting approaches:
Solution 1: Workspace URL Format
Make sure you're using the correct workspace URL format:
Solution 2: Check Unity Catalog Permissions
Solution 3: Minimal Test Setup
Try this minimal version to isolate the issue:
import mlflow
import mlflow.sklearn
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris
# Reset MLflow settings
mlflow.end_run() # End any existing runs
# Minimal configuration
mlflow.set_tracking_uri("databricks")
# Simple model training and registration
X, y = load_iris(return_X_y=True)
clf = RandomForestClassifier(n_estimators=10, max_depth=3)
with mlflow.start_run() as run:
clf.fit(X, y)
mlflow.sklearn.log_model(clf, "iris_model")
run_id = run.info.run_id
print(f"Run ID: {run_id}")
# Wait a moment for the run to finalize
import time
time.sleep(5)
# Try registration with error handling
try:
model_uri = f"runs:/{run_id}/iris_model"
result = mlflow.register_model(
model_uri=model_uri,
name="principal_analysts.nco.iris_simple_test"
)
print(f"Success! Model version: {result.version}")
except Exception as e:
print(f"Registration failed: {type(e).__name__}: {e}")
The "Resource temporarily unavailable" error often indicates either:
1. Insufficient permissions for Unity Catalog model registration
2. Workspace configuration issues
3. Temporary connectivity issues
Try Solution 3 first to isolate the problem, then work backwards to your full implementation.
Passionate about hosting events and connecting people? Help us grow a vibrant local communityโsign up today to get started!
Sign Up Now