aiogevent event loop "fails" to track greenlets aiogevent event loop "fails" to track greenlets python-3.x python-3.x

aiogevent event loop "fails" to track greenlets


Taking a guess at this, but I think you're using the event loop wrong for asyncio. I don't know enough about gevent to understand what type of object it's creating to know if this will work. The documentation would indicate that the order in which stop() and run_forever() are called is relevant to the operational call stack, reading as follows:

If stop() is called before run_forever() is called, the loop will poll the I/O selector once with a timeout of zero, run all callbacks scheduled in response to I/O events (and those that were already scheduled), and then exit.

If stop() is called while run_forever() is running, the loop will run the current batch of callbacks and then exit. Note that new callbacks scheduled by callbacks will not run in this case; instead, they will run the next time run_forever() or run_until_complete() is called.

I'm assuming that this option is being used to control the status of the asynchronous event, but you may find that run_until_complete() may be the better option for you and it may be something like this:

import geventimport aiogeventimport asyncioasyncio.set_event_loop_policy(aiogevent.EventLoopPolicy())loop = asyncio.get_running_loop()async def func():    await print('bloop') # await keyword not needed, just demonstrating    loop.stop()try:    loop.run_until_complete(gevent.spawn(func))finally:    loop.run_until_complete(loop.shutdown_asyncgens())    loop.close()

I added shutdown_asyncgens() incase you are awaiting a yield response which would cause the close() method to hang/fail. I don't have any of these installed to test with, so let me know if this was helpful.


Why don't you just use a while loop like this:

from time import sleepwhile(1 == 1):  print('bloop')  sleep(1)

This will print bloop wait one second then print it again (because 1 = 1), please forgive me if I'm wrong, and you have to use the function you were using, but I gave it my best shot.