[Zope-dev] Threading problem

Dieter Maurer dieter@handshake.de
Sun, 18 May 2003 23:28:07 +0200


Stefan A. Nagey wrote at 2003-5-17 12:07 -0400:
 > I have the following code:
 > 
 >           import threading
 >           thethread = threading.Thread(target=self.addOffice1Page, 
 > args=(REQUEST,))

*Never* pass a persistent object to a thread!

  Persistent objects contain a hidden ZODB connection attribute ("_p_jar").
  The connection provides access to the objects persistent subobjects.
  The connection is closed automatically when the request finished.
  Obscure errors happen when the connection is used thereafter.

Pass an URL instead, get access to the root
("from Zope import app; Root= app()") (this opens a new connection).
and traverse ("unrestrictedTraverse") to your object.
Do not forget to close the connection, once you are done
("some_persistent_object._p_jar.close()").


Dieter