Make a small function thread safe

RangerElf gustavo.cordova at gmail.com
Sun Dec 18 03:52:09 EST 2011


Which is why the original .acquire() ... .release() idiom was wrong, this would better express the intent:

try:
  lock.acquire()
  shared_container.append(...)
finally:
  lock.release()

But like everyone mentions, the with statement takes care of all that in a more readable and compact fashion.



More information about the Python-list mailing list