How the pool works
The recipe’sWarmPool helper starts the configured number of sandboxes and runs
a readiness check in each. Their main processes stay running between commands.
No periodic ping is needed.
Each workload claims one ready sandbox, triggering preparation of a replacement.
Every exec() within that claim shares the same sandbox and files. When the
workload finishes or fails, the helper stops its sandbox. Subsequent workloads
receive separate sandboxes, so they don’t inherit previous workloads’ local state.
Run the recipe
You need Python 3.11+,uv,
and serverless access and credentials.
-
Download or clone the recipe repository and open
recipes/warm-pool. Install dependencies and create your environment file:
-
Vers le début de
demo.py, définissezAUTHsurAuthStrategy.WANDB. Ajoutez votre clé API W&B dans le fichier.enven tant queWANDB_API_KEY, ou utilisez une connexion W&B existante. -
Exécutez la comparaison avec l’authentification W&B, qui requiert sa dépendance facultative :
Adapt the pool to your workload
Edit the constants indemo.py:
WORKLOAD in demo.py with your code. Add shared setup to prepare() in
warm_pool.py and use a readiness check appropriate for your application. Within
an asynchronous workload handler, use the recipe’s claim context for multiple
commands:
Keep the pool running
Keep the pool and enclosingSession contexts open while accepting requests.
Each Python process owns a separate pool. The demo closes both after its comparison.
The helper replaces idle sandboxes at 5 minutes. Each sandbox has a 10-minute
lifetime. The pool continues replenishing while its context is open. Keep jobs
comfortably under 5 minutes with these defaults: claiming a sandbox doesn’t
reset its deadline. For longer-job settings and cleanup after interrupted runs,
see the recipe.
Transient preparation failures get up to three attempts. If those attempts are
exhausted or preparation encounters a non-retryable error, all further claims fail,
even if ready sandboxes remain. Exit the pool and Session contexts to clean up,
then create a new pool when the underlying issue is resolved.
Pour accélérer le réapprovisionnement, intégrez les dépendances stables directement dans votre image ou restaurez
les fichiers préparés de l’espace de travail à partir d’un instantané du système de fichiers.
Les instantanés capturent les fichiers présents dans le point de montage configuré. Les processus applicatifs
doivent néanmoins toujours être démarrés séparément.