On 27/06/2006, at 15:03, Tzahi Fadida wrote:

I am looking for an answer on python threads lock behaviour.

So far, i have not managed to get an answer on #python, 

whatsup,#twisted,google...


You probably need to revise your questions.

If i have many threads running and there is a resource all want

to posses using a lock, i.e., lock.acquire().

one obviously is going to posses the lock.

My question is, when it is released using lock.release() which of the threads

is going to acquire the lock? is it a random process or

a FIFO order. I am trying to understand if starvation is possible

in this particular instance.


I think its undefined.


My other question, is what is more efficient:

using locks, conditions, events, queues. i.e. i am building

a server and i want to avoid unneccessary polling operations.


The question is too general to get any useful answer.


Basically, avoid threads if you can - its hard to program and even harder to test. It also does not scale well with Python because of the GIL, unlike C, most of the time all your threads share the same CPU.


I don't have any idea what is the server you are writing, but I would generally try to use twisted, which will save you lot of time.



Best Regards,


Nir Soffer


לענות