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 ?

C.H
  • 141
  • 1
  • 9
  • Using thread line under http://stackoverflow.com/questions/31623194/asyncio-two-loops-for-different-i-o-tasks : 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 ? – C.H Jan 19 '16 at 15:41
  • You can combine gobject loop with asyncio loop. See my answer for [enter link description here](https://stackoverflow.com/questions/39804102/python-3-4-gtk-async) – Tamás Bajusz Jul 31 '17 at 12:57

1 Answers1

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.

C.H
  • 141
  • 1
  • 9