asyncio loop + GObject.MainLoop
Asked Answered
A

1

6

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 ?

Amphichroic answered 19/1, 2016 at 15:18 Comment(2)
Using thread line under #31623694 : threads = [] t = threading.Thread(target=one_of_function) threads.append(t) t.start() seems working (I did not try to exchange elements yet), but is it clean ?Amphichroic
You can combine gobject loop with asyncio loop. See my answer for enter link description hereTaffrail
A
1

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.

Amphichroic answered 29/1, 2016 at 7:36 Comment(1)
Could you provide a sample usage?Pedate

© 2022 - 2024 — McMap. All rights reserved.