The question is a bit unclear. You need to use semaphores instead of locks or check lock lock.
Python locks are not the same as .Net locks, for example. Python Lock unlocks releases ALL other threads that have acquired () on the same lock and are currently locked. Any stream can be freed, and everything goes at the same time. So, instead of making the second expression, do
if l.locked():
l.release()
"", , , "", "" - , .
, /loolkits, .Net, , lock.acquire , , .
(Edit: "if l.locked: l.realse()". . Lock.locked cPython 2.6.x, 3.x, IronPython 2.6.1)