threading.Semaphore or gevent.lock.Semaphore

dieter dieter at handshake.de
Thu May 25 03:21:45 EDT 2017


Sergey <sh0375 at gmail.com> writes:

> I'm developing Flask app, processed by gevent.wsgi.WSGIServer.
> If I need to isolate some pieces of code inside request handlers, can I use threading.Lock?

This is more a "Flask" than a general Python question.
Accordingly, you likely get a better response in a "Flask" mailing list.

"gevent" is coroutine (not thread) based. This likely means that
you should use "gevent" facilities for synchronisation - not
the "threading" ones.


> If I need semaphore, must I use threading.Semaphore or gevent.lock.Semaphore?
> What is the difference between them?

"threading.Semaphore" is a facility for threads. Unless "Flash"
internally starts threads for request handling (which I doubt),
you should use the "gevent" facility.




More information about the Python-list mailing list