Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start ensure_future once on multiple workers #2346

Closed
obnoxiousish opened this issue Nov 26, 2023 · 0 comments
Closed

Start ensure_future once on multiple workers #2346

obnoxiousish opened this issue Nov 26, 2023 · 0 comments

Comments

@obnoxiousish
Copy link

obnoxiousish commented Nov 26, 2023

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

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@encode encode locked and limited conversation to collaborators Nov 26, 2023
@Kludex Kludex converted this issue into discussion #2348 Nov 26, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant