[Zope] How to create an ansynchronous method

Ron Bickers rbickers-list-zope2 at logicetc.com
Tue Sep 13 17:05:24 EDT 2005


On Tue September 13 2005 02:52 pm, David Pratt wrote:

> Hi. I have a workflow that is triggered by a file upload and the
> processing of the file can be minutes of processing depending upon the
> size of the file uploaded.  I am concerned about number of threads
> available to serve zope so I believe this is a good candidate for an
> asynchronous process.  I am looking for some type of outline to do
> this.  Currently a tool does the work that is triggered by workflow
> script.  My hope is to have this process run and send the user an email
> to advise when the process has completed instead of the user waiting
> for a response or potentially timing out waiting for one. What steps
> could I take to make this an ansynchronous process?

I had to do something like this when processing a lot of data to create PDF 
documents to send via email.  The time to do so was too long for them to sit 
and wait, so I created a separate process to do the job.  I don't know if 
this is the best way, but it wasn't very difficult and it has been working 
without problems for many months.

When a user requests the document, I add a record of needed information to a 
MySQL table (the "queue"), send a signal to the long-running process 
(described next) and immediately return a thank you page.  A 
separate-from-Zope long-running Python process waits for a signal, reads the 
queue table, does what it needs to do, empties the processed items from the 
queue, and goes idle.  It can handle things like getting a signal while it's 
processing a queue and "catching up" occassionally if it missed a signal 
(for whatever reason).

Hope this helps.

-- 
Ron


More information about the Zope mailing list