Dear all, I need a sort of post-publishing hook (so to say). I need Zope to call a function of mine as the very last action of publishing a request, i.e. after having built the response (and sent it to the browser possibly), but before starting publishing a new request. My Zope server is running as a single-threaded app. Does Zope support this any way? Thanks for helping, cheers, Carlo.
On Friday 29 November 2002 12:07 pm, Carlo Giomini wrote:
Dear all, I need a sort of post-publishing hook (so to say). I need Zope to call a function of mine as the very last action of publishing a request, i.e. after having built the response (and sent it to the browser possibly), but before starting publishing a new request. My Zope server is running as a single-threaded app. Does Zope support this any way?
Yes, but its nasty. Look at ZPublisher.BaseRequest._hold
Hi Carlo, --On Freitag, 29. November 2002 13:07 +0100 Carlo Giomini <c.giomini@caspur.it> wrote:
Dear all, I need a sort of post-publishing hook (so to say). I need Zope to call a function of mine as the very last action of publishing a request, i.e. after having built the response (and sent it to the browser possibly), but before starting publishing a new request. My Zope server is running as a single-threaded app. Does Zope support this any way?
May be. But what are you trying to do? Perhaps there is a better solution available if we know the whole picture. Regards Tino
On Fri, Nov 29, 2002 at 01:07:24PM +0100, Carlo Giomini wrote:
Dear all, I need a sort of post-publishing hook (so to say). I need Zope to call a function of mine as the very last action of publishing a request, i.e. after having built the response (and sent it to the browser possibly), but before starting publishing a new request. My Zope server is running as a single-threaded app. Does Zope support this any way?
There is a way, but I find it somewhat ugly/hackish. But Shane uses it in CookieCrumbler, so it must be good ;) You can pass an instance to REQUEST._hold, which should be deleted when REQUEST gets deleted, so at the complete end of the request. This means you can pass an instance to a class that defines a __del__ method, where you can do your work. You'll be working outside the REQUEST transaction at that moment, so please keep that in mind when modifying objects. Cheers Ivo -- Drs. I.R. van der Wijk -=- Brouwersgracht 132 Amaze Internet Services V.O.F. 1013 HA Amsterdam, NL -=- T +31-20-4688336 F +31-20-4688337 Linux/Web/Zope/SQL/MMBase W http://www.amaze.nl E info@amaze.nl Network Solutions W http://vanderwijk.info E ivo@amaze.nl Consultancy PGP http://vanderwijk.info/pgp -=-
On 11/29/2002 01:33 PM, Ivo van der Wijk wrote:
On Fri, Nov 29, 2002 at 01:07:24PM +0100, Carlo Giomini wrote:
Dear all, I need a sort of post-publishing hook (so to say). I need Zope to call a function of mine as the very last action of publishing a request, i.e. after having built the response (and sent it to the browser possibly), but before starting publishing a new request. My Zope server is running as a single-threaded app. Does Zope support this any way?
There is a way, but I find it somewhat ugly/hackish. But Shane uses it in CookieCrumbler, so it must be good ;)
"Reliable" and "good" are not necessarily the same thing. :-) Since the only way ZODB connections ever get closed in a standard Zope setup is through the request.hold() mechanism, you can be sure that if Zope is working at all, the side effects of request.hold() are working. Relying on side effects can be dangerous, though.
You'll be working outside the REQUEST transaction at that moment, so please keep that in mind when modifying objects.
In fact, the database connection might already be closed. If you need to read or write the ZODB, you might have to open a private connection and close it before returning. Ugh. Shane
Shane Hathaway <shane@zope.com> wrote:
On 11/29/2002 01:33 PM, Ivo van der Wijk wrote:
On Fri, Nov 29, 2002 at 01:07:24PM +0100, Carlo Giomini wrote:
Dear all, I need a sort of post-publishing hook (so to say). I need Zope to call a function of mine as the very last action of publishing a request, i.e. after having built the response (and sent it to the browser possibly), but before starting publishing a new request. My Zope server is running as a single-threaded app. Does Zope support this any way?
You'll be working outside the REQUEST transaction at that moment, so please keep that in mind when modifying objects.
In fact, the database connection might already be closed. If you need to read or write the ZODB, you might have to open a private connection and close it before returning. Ugh.
Indeed, the connection has already been closed at that point so you will need to open a new one. Note also that you won't be able to report any error to the user (obviously). Florent -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
participants (6)
-
Carlo Giomini -
Florent Guillaume -
Ivo van der Wijk -
Shane Hathaway -
Tino Wildenhain -
Toby Dickenson