Start ensure_future once on multiple workers #2348
Unanswered
obnoxiousmods
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
How would I go about properly running ensure_future only once on a function/coroutine in a starlette + uvicorn combo that uses --workers in uvicorn
Currently I am using the starlette startup event to execute asyncio.ensure_future() on a function that loops grabbing exchange rates from a HTTP API, and if --workers is 8, then i believe it creates 8 of these loops which isnt ideal
How would I go about sharing this loops data with all of them/only executing it once between them all
Is there not an easy solution to this problem?
I suppose I could create a new process specifically for this data that updates it in mongodb and have them all grab it from there, but kind of a lame solution.
Thanks for any time spent reading or replying to my problem!
Important
Beta Was this translation helpful? Give feedback.
All reactions