[ZODB-Dev] nontransactional, oid, and thread safety. oh my!

Tim Peters tim at zope.com
Sun Oct 3 20:45:54 EDT 2004


[Dmitry Vasiliev]
...
> Is it safe to use code like this:
>
> def do_changes():
>      lock.acquire()
>      try:
>          do_obj_changes()
>          transaction.commit()
>      finally:
>          lock.release()
>
> ?

If you have only one thread, certainly.  In the absence of knowing
everything this app is doing, I'm not going to guess.  OTOH, if you do
reveal everything this app is doing, I won't have time to guess <wink>.  For
example, as was said last time, each thread should have its own connection
to the database; there's not enough above to guess whether that's so; the
only real explanation for thread edge cases I know of in ZODB now is "if you
use threads exactly the way Zope uses them, that's safe"; as a fine point,
in ZODB 3.3 you must explicitly discard a transaction that fails, so you at
least need to defend against commit() failure in the above (threaded or
not).



More information about the ZODB-Dev mailing list