[Zope] Polling a folder

Dieter Maurer dieter@handshake.de
Tue, 3 Sep 2002 21:48:18 +0200


GimsMail writes:
 > I have tried creating a polling object that runs a loop in a thread and does
 > the work I want it to do. I do this with a Zope Object inheriting from
 > SimpleItem.SimpleItem.  I invoke this object's run method in a thread with
 > thread.start_new_thread(self.run,()).  Zope doesn't seem too happy if I
 > inherit from SimpleItem.SimpleItem and threading.Thread at the same time!
You cannot access a persistent object from a different thread than it
was loaded in.

You can do the following:

  *  pass the object path into your thread method: "path"

  *  Inside the thread use:

	    from Zope import app; root= app()
	    object= app.unrestrictedTraverse(path)

     Now, use "object" as you like.

     If it changes something, do not forget to call
     "get_transaction().commit()".

     Please read the "zodb3" documentation. Otherwise, you will
     meat more surprises...


Dieter