Search code examples
python-3.xpygobjectpython-asyncio

asyncio loop + GObject.MainLoop


I have coded something with an asyncio loop:

loop = asyncio.get_event_loop()
# bla coroutines
loop.run_forever()

and now, someone gives to me a part of code using a GObject.MainLoop()

l = GObject.MainLoop()
# functions using gi.repository I cannot modify, bla
l.run()

I am supposed to integrated this code in the same software than mine (with asyncio). And theses piece of code have to run simultaneously. The parts of code have to exchange objects.

I am not sure of which solution would appropriated or, at least, not too ugly ?

ps: this code has to run on windows OS and python3.4, so I cannot used glub. I supposed I could use threads, but I would to know if there is another way ?


Solution

  • Finaly, it works with 2 threads like in my preceding comment. But the communication between queue (asyncio.Queue and queue.Queue) was really too long. I discovered the janus library (thread-safe queue compatible with asyncio), and it work perfectly.