Hi Etienne, thanks for your help. Now the web application is working as I expect it to work. Your tip about the creation of the connection was the last missing piece of the puzzle. Regards Florian Reiser -----Ursprüngliche Nachricht----- Von: Etienne Labuschagne [mailto:elabuschagne@gmsonline.co.za] Gesendet: Donnerstag, 17. Juli 2003 19:15 An: florian.reiser@ra-bc.de; 'Chris Withers' Cc: 'Zope-allgemein' Betreff: Re: AW: [Zope] Threading in Zope Florian, Your new thread, does it need to change any Zope objects, or will it process the PDF file and exit without changing any Zope objects? If you are going to change Zope objects, you will have to create a new connection into the ZODB, because passing Zope objects to new threads is A VERY BAD IDEA. If your threads do not change any Zope objects, it should be no problem, i.e. starting a thread and only passing it the path where the PDF will be created should be fine. In general, passing any immutable object should be fine (no, not tuples containing mutables!). Passing Zope objects, and changing stuff on those objects . . . well, prepare to start gnawing off you own leg or something :) The way I use Zope objects thread safely (please Chris, Dieter, or anyone else correct me if I'm wrong!) goes something like this: def myNewThreadMethod(pathToZopeObject): connection = Globals.DB.open(force=1) #you have a connection into the DB (remember to import Globals) app = connection.root()['Application'] #now we have the Zope root object myObject = app.unrestrictedTraverse(pathToZopeObject) #we go and fetch the object # maybe get the user object and log in as user here (see other responses) if you want to myObject.doAllKindsOfStuff() #do whatever you want to get_transaction().commit() #or get_transaction().abort() if you don't want the changes to stick (very important) app._p_jar.close() #close the connection into the DB def methodThatStartsNewThread(self, REQUEST, whateverElse): myObjectThatIWannaUseInAThread = self.howeverIGetToIt() #you now have a Zope object - you cannot pass this to another thread! pathToMyObject = myObjectThatIWannaUseInAThread.getPhysicalPath() #get the physical path relative to the root thread.start_new(myNewThread, (pathToMyObject)) #fire up your method, passing it the path to the object This may have Chris, Dieter and the likes gasping with shock and horror at #1 either the wrongness (I'm sure this isn't too wrong), or #2 the inelegance of it, but so far it works for me. Understand that you cannot get your hands on a Zope object in one thread and pass it to another thread to be changed. This will lock up Zope and in general make your whole life miserable. You may get away with passing the object for read only type access, but I don't bargain on it and don't do it (gets glazed look, remembering loooong nights of suffering) I hope that either this helps, or at least scares you off of doing it half heartedly and getting burnt! Regards and good luck Etienne At 02:39 PM 17/7/2003 +0200, Florian Reiser wrote:
No I'm not. Perhaps I should explain you my problem.
I have a zope object which compiles a huge pdf file for about 5 minutes
or so. At some point an intermediate ISA server (M$ ;)) times out and sends an error page to the browser. Due to the error page the browser ignores the redirect header in the response. The redirect header should point the browser to a waiting page, which checks every 10 seconds, if the pdf file is generated yet. However IE sets the URL of the browser to the one received in the redirect header, but does not reload the window.
Now I want to compute the pdf-file in a separate thread, so the originating one can return and show the redirection page before the ISA
server times out.
If you have another solution for me, how I can cause Zope the end the response before the method returns, I would be glad to hear it.
Regards Florian Reiser
-----Ursprüngliche Nachricht----- Von: Chris Withers [mailto:chrisw@nipltd.com] Gesendet: Donnerstag, 17. Juli 2003 14:29 An: florian.reiser@ra-bc.de Cc: 'Zope-allgemein' Betreff: Re: [Zope] Threading in Zope
Florian Reiser wrote:
Hi folks,
When I start a thread in zope, which shall execute a zope object, then
the user falls back to the 'Anonymous User'.
How can I preserve the current user for the thread? I need the user, because the script assembles it's output according to
the users rights.
You need seriously deep Zen to do this kind of programming... Are you _really_ sure you want to? ;-)
cheers,
Chris
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )