30

I'm trying to create a GUI framework that will have an event-loop. some threads to handle the UI and some for event handling. I've searched a little bit and found these three libraries and I'm wondering which one is better to use? what are the pros and cons?

I could use one of these three library or even create something for myself by using python threads, or concurrent library.

I would appreciate sharing any kind of experience, benchmark and comparison.

mehdy
  • 3,174
  • 4
  • 23
  • 44

1 Answers1

29
  • You definitely don't want greenlet for this purpose, because it's a low level library on top of which you can create light thread libraries (like Eventlet and Gevent).
  • Eventlet, Gevent and more similar libraries provide excellent toolset for IO-bound tasks (waiting for read/write on file, network).
  • Likely, most of your GUI code will wait for other threads (at this point green/light/OS thread is irrelevant) to finish, which is a perfect target for above mentioned libraries.
  • All green thread libraries are mostly the same. Try all and decide which one suits your project best.
  • But also it's possible that you'll need to extract some things into a separate OS thread due to requirements of OS level GUI layer.
  • Considering that and better implementation of thread lock in Python3 you may want to just stick with native threading module if your application doesn't need hundreds or more threads.
temoto
  • 5,394
  • 3
  • 34
  • 50
  • 3
    So much for "There should be one-- and preferably only one --obvious way to do it.". I'd use [`multiprocessing`](https://docs.python.org/3/library/multiprocessing.html). – Cees Timmerman Sep 01 '18 at 05:19
  • Wait what!! If it is I/O bound task then using multiprocessing is just a waste of resources isn't it, as other cores can be used for several other processes – onlinejudge95 Nov 05 '21 at 13:00
  • @onlinejudge95 when a thread/process blocks on I/O, OS would use core for others. It's less efficient than epoll/kqueue/etc, but does not stall. It's actually OK approach up to around 200 threads. – temoto Nov 06 '21 at 06:13