Re: [Zope3-Users] Re: Request in Zope3-Thread
Hi Philipp, hi list, maybe I'm wrong, but after several tests i have noticed this change (caused by threading environment): ... setSite(old_site) transaction.get().commit() conn.close() ... with transaction.commit() there are some: ZODB.POSException.ConnectionStateError: Cannot close a connection joined to a transaction under special circumstances (more threads, some commits) Does this transaction.get()... is the right way to interact with the Thread-aware transaction manager? Markus Am Samstag 04 August 2007 um 11:13 Uhr schrieb Philipp von Weitershausen [EMAIL PROTECTED]: Markus Leist wrote: i have created a thread in my zope3-application like the zope.sendmail.QueueProcessorThread. What i want to do: fake a request-context to get a local Utility (via Sitemanager) configured in ZODB and call some methods which will change some object-attributes in ZODB. You'll have to open a new connection to the database in the thread and get the root object from it (you'll have to give the thread a reference to the database, which can be accessed from any persistent object thru obj._p_jar, IIRC): conn = db.open() root = conn.root() root_folder = root['Application'] Now you can traverse to the site that contains the local utilities (unless that's the root_folder) and make the current active site (current = for this particular thread): from zope.app.component.hooks import setSite site = root_folder['path']['to']['the']['site'] setSite(site) Now do your component lookups, object modifications, etc. Don't forget to commit the transaction at the end: import transaction transaction.commit() and close the connection: conn.close() ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: Request in Zope3-Thread
On 20 Aug 2007, at 19:29 , Markus Leist wrote: maybe I'm wrong, but after several tests i have noticed this change (caused by threading environment): ... setSite(old_site) transaction.get().commit() conn.close() ... with transaction.commit() there are some: ZODB.POSException.ConnectionStateError: Cannot close a connection joined to a transaction under special circumstances (more threads, some commits) Does this transaction.get()... is the right way to interact with the Thread-aware transaction manager? transaction.get().commit() should be completely equivalent to transaction.commit(). The setSite(old_site) call doesn't look necessary since the reference to the site is local to the thread. Am Samstag 04 August 2007 um 11:13 Uhr schrieb Philipp von Weitershausen [EMAIL PROTECTED]: Markus Leist wrote: i have created a thread in my zope3-application like the zope.sendmail.QueueProcessorThread. What i want to do: fake a request-context to get a local Utility (via Sitemanager) configured in ZODB and call some methods which will change some object-attributes in ZODB. You'll have to open a new connection to the database in the thread and get the root object from it (you'll have to give the thread a reference to the database, which can be accessed from any persistent object thru obj._p_jar, IIRC): conn = db.open() root = conn.root() root_folder = root['Application'] Now you can traverse to the site that contains the local utilities (unless that's the root_folder) and make the current active site (current = for this particular thread): from zope.app.component.hooks import setSite site = root_folder['path']['to']['the']['site'] setSite(site) Now do your component lookups, object modifications, etc. Don't forget to commit the transaction at the end: import transaction transaction.commit() and close the connection: conn.close() ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: Request in Zope3-Thread
Hi, i don't understand, you are right: class TransactionManager(object): def commit(self): return self.get().commit() after deletion of setSite(old_site) it seems to be better, but under some circumstances there still is: ZODB.POSException.ConnectionStateError: Cannot close a connection joined to a transaction (sometimes). Hmm, it's hard to debug this part of my app. I will do some kind of printf-debugging in a few days. the problem appears in an error-handler of my app ... and there are no errors in/with the application ;-) Thanx for the quick answer. Markus Am Montag 20 August 2007 um 19:30 Uhr schrieb Philipp von Weitershausen [EMAIL PROTECTED]: [...] transaction.get().commit() should be completely equivalent to transaction.commit(). The setSite(old_site) call doesn't look necessary since the reference to the site is local to the thread. ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users