Replies: 2 comments 4 replies
-
|
Beta Was this translation helpful? Give feedback.
-
I would like to second the need for an unique identifier for each worker that is also consistent(!) across restarts. I currently have a use case where I need to limit multiple resources for a synchronous REST API and that relates to the integrity of application state that is shared among all workers. This state is mutated by a background task that runs in each worker. I would need to provide an idempotent startup/shutdown routine to clean up any inconsistencies caused by a potential crash of any of my workers (such a thing could happen with any unforeseen kill of the worker process). Without being able to differentiate between each worker in a way that is consistent across restarts I currently cannot make this routine idempotent. As a workaround I implemented the background task to start with the acquisition of a lock that is shared among all worker - if the lock is aquired the background task starts, otherwise it's waiting (until the one worker with the aquired lock is killed/restarted). Unfortunately this limits my background tasks to a single instance for all workers instead of having one for each worker. An implementation could as simple as passing the |
Beta Was this translation helpful? Give feedback.
-
Hi,
Is it possible to get a unique integer ID for each worker when running Uvicorn in multi-process mode(--workers option) ? Instead of relying on PIDs, which can change, having an ID that ranges from 1 to the number of workers specified with --workers=WORKERS would be useful for instrumentation
Beta Was this translation helpful? Give feedback.
All reactions