Noob thread lock question

Diez B. Roggisch deets at nospam.web.de
Wed Dec 2 14:43:46 EST 2009


Astley Le Jasper schrieb:
> I have a number of threads that write to a database. I have created a
> thread lock, but my question is this:
> 
> - If one thread hits a lock, do a) all the other threads stop, or b)
> just the ones that come to the same lock?

Only the ones coming the the same lock.

> - I presume that the answer is b. In which case do the threads stop
> only if they come to the same instance of a lock. For example, you
> could have a lock instance for one database and another instance for
> another database (first_db_thread_lock = threading.RLock() ....
> second_db_thread_lock = threading.RLock()).


There is nothing like "not an instance of a lock". So it's essentially 
the same question as the first, and thus the answer is also: yes, only 
for the *same* lock, which is an instance.

Diez



More information about the Python-list mailing list