pythonasynchronousnonblockinggreen-threadsgreenlets

Is blocking an issue with greenlets?


I understand blocking code is a sin when it comes to event loops (i.e. NodeJS), but what about with greenlets (which I believe are green threads)? Is there an issue running code that calls blocking functions?


Solution

  • Greenlets themselves without an event loop as provided by gevent are very primitive. A blocking call from within one greenlet will block all greenlets since greenlets alone have no capability to yield on IO operations, and no scheduler. Gevent's monkey-patching of socket and file IO is generally enough to enable non-blocking IO even with databases provided that the database library is written in python and uses sockets. Or alternately you can patch the library yourself.