[Zope-dev] Threading problem

Stefan A. Nagey stefan@ispvip.biz
Sat, 17 May 2003 12:07:46 -0400


I have the following code:

          import threading
          thethread = threading.Thread(target=self.addOffice1Page, 
args=(REQUEST,))
          thethread.setDaemon(0)
          thethread.start()
          return threading.enumerate()

This is it's output:
[<_MainThread(MainThread, started)>, <_DummyThread(Dummy-3, started 
daemon)>, <_DummyThread(Dummy-2, started daemon)>, 
<_DummyThread(Dummy-1, started daemon)>, <_DummyThread(Dummy-4, started 
daemon)>, <Thread(Thread-7, started)>]

when I call the method, it does tell me that the thread has been 
started. However, it seems that as soon the request returns, the thread 
that I have just started exits.

If I call self.addOffice1Page(REQUEST) it works just fine, and as 
expected, no errors. But when I call the thread, nothing happens (i 
know this because i have a OOBTree that stores the info, and the thread 
should change part of that when it starts processing, like the first 
thing it does.).


The problem that I am trying to solve with this is that my process to 
add an acount takes some time to process, so what I am trying to do is 
spin off the thread that actually does the processing so that the 
client can get a page back that says that their account is processing, 
a la expedia or travelocity. And when the client reloads the helper 
page, it will check the status and take the appropriate action.

So, my question is, What is the (undoubtedly very simple) thing that I 
am missing that makes it so that this will work?

Or, should I just queue them and run a cron job every five minutes to 
process whatever might be in the queue?

Any help would be so very much appreciated.

oh, zope 2.5.1, python 2.2.2, behind apache 1.3.27 running on linux 
2.4.20