You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, this project is great! Thanks for putting it together.
I've been experimenting with running asyncio functions in gevent with loop.run_forever. I had trouble getting the asyncio loop to actually run any scheduled tasks because the event loop would never be notified when create_task is called because calling create_task does not notify selector.select. I was able to resolve this by making EventLoop.call_soon call self._write_to_self() in the same way that EventLoop.call_soon_threadsafe does, to notify the selector.
Something like this:
class GeventEventloop(asyncio.SelectorEventLoop):
def __init__(self, selector=None):
super(GeventEventloop, self).__init__(selector or gevent.selectors.DefaultSelector())
def call_soon(self, callback, *args, context=None):
handle = super(GeventEventloop, self).call_soon(callback, *args, context=context)
self._write_to_self() # Without this, it never runs the task function
return handle
loop = GeventEventloop()
loop_greenlet = gevent.spawn(loop.run_forever)
loop_greenlet.start()
async def logit(text):
print(text)
def callit(fn, *args):
task = loop.create_task(fn(*args))
event = gevent.event.Event()
def done(_):
event.set()
task.add_done_callback(done)
event.wait()
return task.result()
greenlets = []
for i in range(20):
greenlets.append(gevent.spawn(callit, logit, "meow"))
gevent.wait(greenlets)
I'm curious if I'm doing something wrong, or if there is something useful to add to the framework or docs.
The text was updated successfully, but these errors were encountered:
Hi, this project is great! Thanks for putting it together.
I've been experimenting with running asyncio functions in gevent with loop.run_forever. I had trouble getting the asyncio loop to actually run any scheduled tasks because the event loop would never be notified when create_task is called because calling create_task does not notify selector.select. I was able to resolve this by making EventLoop.call_soon call self._write_to_self() in the same way that EventLoop.call_soon_threadsafe does, to notify the selector.
Something like this:
I'm curious if I'm doing something wrong, or if there is something useful to add to the framework or docs.
The text was updated successfully, but these errors were encountered: