-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
UniversalQueue ala curio #449
Comments
There's sample code at the end of this chapter: |
Yeah, the simplest approach is to create a Trio doesn't have Curio's feature of magically introspecting the calling context to automatically decide which functions should be wrapped in a call to class BlockingQueueWrapper:
def __init__(self, queue, portal):
self.queue = queue
self.portal = portal
def put(self, value):
self.portal.run(self.queue.put, value)
def get(self):
return self.portal.run(self.queue.get, value)
def put_nowait(self, value):
self.portal.run_sync(self.queue.put_nowait, value)
def get_nowait(self):
return self.portal.run_sync(self.queue.get_nowait) Then you can do something like: queue = trio.Queue()
portal = trio.BlockingTrioPortal()
blocking_queue = BlockingQueueWrapper(queue, portal)
await run_sync_in_worker_thread(my_func, blocking_queue) and Or maybe it's possible to automatically generate class wrappers like this, so we could have |
Does that help? |
Yes that helps, thanks. I actually did end up doing the reverse, wrapping the stdlib Queue and calling |
The portal way will certainly use less worker threads; I can't say if that will be more performant or not without measuring :-). The other difference to be aware of is that when you're using the queue from trio, then the |
Thanks. By the way, I found your articles on async extremely insightful, and the way that trio really thinks through the various async control flow issues is just very attractive. |
I need to run a consumer in an OS thread. I want to communicate with a queue. curio tells me I should use their UniversalQueue, the purpose being that it blocks correctly from within curio and from within the thread.
I can't find an equivalent in trio (maybe I missed it?).
The text was updated successfully, but these errors were encountered: