[Zope] How to create an ansynchronous method

Ron Bickers rbickers-list-zope2 at logicetc.com
Tue Sep 13 23:11:26 EDT 2005


On Tue September 13 2005 08:16 pm, David Pratt wrote:

> How is it that you send a signal to the long running
> process?

The long-running process writes a pid file and waits for a SIGUSR1 signal 
(using Python's signal module).  A small External Method, called when the 
user submits the form, reads the pid file and sends the signal to the 
process.

> Is the long running process cronned to look for a record in 
> the database or is this starting another server of some type.

It waits for a SIGUSR1 signal from the website, otherwise it's idle.  That 
way it can begin processing immediately but doesn't have to do any periodic 
checking.  I do, however, have a cron job that starts it every 15 minutes in 
case it dies.  The process knows if it's already running, so it's safe to 
just start it regularly.

> What I need is something like what you are suggesting - wakes up when
> there is work in the hopper and chugs along until it is done and then
> goes to sleep (sort of the way a printing queue works). At the same
> time it would be great if it was something that had a small RAM
> footprint or ran without consuming any more than X mbs.

The part that waits for the signal is very small, but it loads the Reportlab 
modules and reads a bunch of data to do the work, so it can get large at 
times.  If it were to just call an external program that dies after doing 
its work, you could easily keep memory usage low.

> The other 
> problem I have with this is that it needs to do work in Zope itself
> since the final docs end up as objects.  I have just found Chris
> Wither's product called Stepper. I am not sure it this is for this type 
> of situation or more for cronned maintenance.

I have no idea.  Maybe it'll do what you want, but I don't understand what it 
really does just from the description.  The work I needed to do was external 
to Zope anyway (reading data from a MySQL database, building PDFs with 
Reportlab, sending email), so it's actually better that I'm outside of it.

When I have to run things in Zope from outside, I run curl with a URL of a 
Python Script that does the work.  It's a hack, but I've never had a problem 
with it.  I'm not sure how else you would work in Zope from a process 
outside of Zope.

-- 
Ron


More information about the Zope mailing list