Gabor Hosszu
07/17/2025, 5:15 PMMarvin
07/17/2025, 5:15 PMMarvin
07/17/2025, 5:15 PMbash
# Environment variable approach
export PREFECT_CLIENT_MAX_RETRIES=10 # Default is 5
2. Timeouts
There are several timeout-related settings you can configure:
bash
# API request timeout
export PREFECT_API_REQUEST_TIMEOUT=120 # in seconds
# Database timeout
export PREFECT_SERVER_DATABASE_TIMEOUT=30 # in seconds
3. Configuration File Approach
Alternatively, you can set these in your Prefect configuration file (typically at ~/.prefect/profiles.toml
):
toml
[client]
max_retries = 10
retry_jitter_factor = 0.2 # Optional: adds randomness to retry timing
[server.database]
timeout = 30
Important Notes:
- These settings affect all Prefect operations, not just .serve()
- The retry mechanism includes jitter by default to prevent thundering herd problems
- If you're experiencing timeout issues, it's recommended to:
1. First check your network connectivity
2. Consider increasing the database timeout if you're seeing database-related issues
3. Adjust the client retries if you're seeing connection issues
Links to relevant documentation:
- Prefect 3.x Settings Reference
Remember that these are global settings that will affect all Prefect operations, not just .serve()
. If you're experiencing specific timeout issues, you might want to investigate the root cause as increasing timeouts might just mask underlying problems.Gabor Hosszu
07/17/2025, 5:39 PMMarvin
07/17/2025, 5:39 PMread_github_issues
📊 Tools used:
• display_callable_signature
(272x)
• explore_module_offerings
(101x)
• read_github_issues
(17x)
• research_prefect_topic
(16x)
• review_common_3x_gotchas
(16x)
• search_prefect_3x_docs
(117x)Marvin
07/17/2025, 5:41 PMMarvin
07/17/2025, 5:42 PMbash
# Set to 0 retries so it fails immediately
export PREFECT_CLIENT_MAX_RETRIES=0
# Set a very short timeout (in seconds)
export PREFECT_API_REQUEST_TIMEOUT=1
# Alternatively, you can set these in your ~/.prefect/profiles.toml:
[client]
max_retries = 0
[api]
request_timeout = 1
You can set these environment variables before running your script that contains the computer_vision_flow.serve()
call.
This configuration will:
1. Disable retries completely (max_retries=0
)
2. Set a very short timeout of 1 second for API requests
3. Cause the serve process to fail quickly if it can't reach the Prefect server
You might also want to add error handling in your code:
python
from prefect.exceptions import PrefectHTTPStatusError
try:
computer_vision_flow.serve()
except PrefectHTTPStatusError as e:
print("Lost connection to Prefect server")
# Add any cleanup code here
raise
Important Notes:
- These settings will affect ALL Prefect operations in your environment, not just this specific flow
- If you only want these settings for this specific flow, you might want to set them just before running the serve command and reset them afterward
- Make sure your error handling code can properly clean up any resources your flow might be using
This configuration should give you the "fail fast" behavior you're looking for when the Prefect server becomes unavailable.