[ZODB-Dev] BTreeFolder2 causes "RuntimeError: Shouldn't load state for"?

Marius Gedminas mgedmin at b4net.lt
Thu Jul 22 11:17:00 EDT 2004


On Thu, Jul 22, 2004 at 10:25:18AM +0200, Syver Enstad wrote:
> Is it okay to just read persistent objects after a thread has modified
> them? Since I am using ZODB with Twisted web I am thinking of the
> following scenario. Since twisted has a mainloop it would be prudent
> to shuffle off a long running operation involving ZODB to a thread so
> that other web requests can be handled. After the thread has finished
> processing I want to display the object(s) that changed.

SchoolTool does that.  Take a look at the Request class in

  http://source.schooltool.org/svn/trunk/schooltool/src/schooltool/main.py

> Sketch:
> 
> In the web page (mainloop):
> 
> Open a new connection: (I am always using setLocalTransaction to not
> make the transaction thread bound).  Spawn off a thread and pass the
> connection to it. Set up a callback for further processing when the
> thread is done.
> 
> In worker thread:
> Do processing 
> connection.getTransaction().commit()
> return interesting Persistent objects.

I think this will not work.  You need to open ZODB connections in worker
threads.

> In the web page (mainloop):
> Receive result in callback and display it (generate html).
> 
> If this is not possible I'd like to hear why.

"You cannot pass Persistent objects from one thread to another" seems to
be unambiguous to me.  ZODB/transaction code contains some per-thread
caches/registries.

I might be wrong, as I haven't studied the internals of ZODB deeply.  It
seemed to me that it is prudent to choose the same model Zope uses,
that is, open new ZODB connections for every request in worker threads.

Marius Gedminas
-- 
Get a life?  Well, once I nearly found one, but the link was broken.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zodb-dev/attachments/20040722/4fd86614/attachment.bin


More information about the ZODB-Dev mailing list