Is there any difference between threading.Lock()
, threading.Semaphore()
behaviour in usual python thread and greenthread (eventlet)?
There is no difference in the behavior. However, green thread isn't actually a thread since it runs all its tasks in a single OS thread, so the threading.Lock
and threading.Semaphore
will behave as if it's being locked and unlocked from a single thread.
This means if you try to acquire a locked Lock or an zeroed Semaphore when using green threads, then the whole program will block forever (or until the specified timeout). Also, an RLock can only be released from the same thread it's locked, since green threads actually all run on the same thread you will be able to release an RLock from a different green thread.
In short, don't use threading
locks when using green threads.