janus icon indicating copy to clipboard operation
janus copied to clipboard

No running event loop

Open aaronclong opened this issue 3 years ago • 6 comments

I am having trouble creating the janus Queue outside of asyncio. It requires me to make dummy background tasks to just create the object, since not running loop exists I am wonder if this could be lazy or allow the loop to be passed in the constructor? It makes sync to async code a tad harder.

aaronclong avatar Oct 25 '22 19:10 aaronclong

I was able to use janus v0.4.0 successfully but upgrading to v1.0.0 results in the same code raising RuntimeError: no running event loop. I haven't been able to pin down the exact change that caused this.

blozano824 avatar Feb 14 '23 23:02 blozano824

From my understanding it needs an existing asyncio loop in main thread in order to work. I tried to force it to use a loop from separate thread but it didn't like that.

lemonJumps avatar Feb 17 '23 09:02 lemonJumps

actually, I've found this https://github.com/dano/aioprocessing it has a queue that works like a charm. <3

lemonJumps avatar Feb 17 '23 10:02 lemonJumps

I suspect problem as described here https://github.com/aio-libs/janus/pull/438

jettify avatar Mar 18 '23 21:03 jettify

Any progress of this Issue? Same problem when I creating a queue in the sync function and pass it to the async one.

ghost avatar Mar 21 '23 12:03 ghost

Simple way to create janus queue in synchronous code (Python 3.6+).

import asyncio
import janus

def init_janus_queue(loop: asyncio.AbstractEventLoop):
    async def create_queue():
        return janus.Queue()
    return loop.run_until_complete(create_queue())

#create your own loop before initializing, note that the loop must remain the same afterword
#loop = asyncio.new_event_loop()
#asyncio.set_event_loop(loop)

res_queue = init_janus_queue(loop)

OppOops avatar Jun 17 '24 08:06 OppOops