Best way to spawn process on back end computer

Paul Boddie paul at boddie.org.uk
Thu Oct 16 16:17:54 CEST 2008


On 16 Okt, 15:51, Robin Becker <ro... at reportlab.com> wrote:
> sophie_newbie wrote:
> > I'm running a python cgi script on a frontend web server and I want it
> > to spawn another script (that takes a long time to run) on a backend
> > number crunching server thats connected to the same network. What do
> > you think is the best way to do this? I have a few ideas but I'm sure
> > there is a "best" way to go about this.
>
> The main problem here is that you'll probably need to detach the job to allow
> the current cgi request to return a response to the client.

I've added support for background processes to the pprocess library;
this attempts to address the problems around detaching from worker
processes and re-attaching to them later in order to collect the
results:

http://www.boddie.org.uk/python/pprocess/tutorial.html#BackgroundCallable

Arguably, this is more complicated than the most basic approach, which
would involve having separate, spawned processes just writing to files
whose contents would then be passed back to the user or processed in
the CGI script, but it's the notification that's the most difficult
part, not the data transfer: efficiently getting a notification event,
rather than polling stuff frequently, is the main problem.

> The implication of that is that the job either has to be anonymous and requires
> no further attention or you need to provide some means of making the job
> responsive to requests about its status so that a periodic request can be made
> by the web page. That implies that the job can be identified and the creation
> reponse returns the identity. One of the major problems is that the normal www
> user has few privileges and cannot normally write to disk.

I've used UNIX sockets as the means of communication between creating/
collecting processes (the CGI script in this case) and the created/
worker processes. Someone suggested an alternative method of binding
to kernel-managed namespaces, if I recall the nature of the suggestion
correctly, but I haven't looked into this yet.

More details here:

http://www.boddie.org.uk/python/pprocess.html

And for the impatient, a repository is here:

https://hg.boddie.org.uk/pprocess

Paul



More information about the Python-list mailing list