[mod_python] os.system() call does not work within mod_python script

Graham Dumpleton grahamd at dscpl.com.au
Sat May 14 19:21:27 EDT 2005


On 15/05/2005, at 8:08 AM, Arno Wilhelm wrote:

> Hello,
>
> I have got a proble for which I cannot find a proper solution:
>
> Whenever a user on his browser hits a certain page (served by 
> mod_python) the mod_python should send a SIGUSR signal to a certain 
> process in order to force a update on him like this
>
> # os.system( "kill -s SIGUSR1 26199" )
>
> Whenever I make this call from within a python script it works. But 
> whenever I try to build it into the mod_python script that is handled 
> by apache it does not work. After that I have experimented with other 
> os.system calls from within mod_python scripts and all of them seem to 
> be ignored somehow.
>
> Could someone here possibly shed some light on this issue, since I am 
> on the end of my knowledge.

A few things to consider.

1. Set full pathnames to the programs in the command.

The PATH setup for Apache may not be that useful. It may reference
some standard locations, but not much. Thus, if you expect program
to be found by searching PATH, it may not work.

2. Don't rely on the current working directory to be anything specific.

Normally current working directory would be '/' and nothing to to do
with where any Python request handler will be. Any references to files
should always be as absolute paths.

3. Apache usually runs as user "nobody" or some other special user.

Because Apache runs as a special user, it often will not have the
necessary privileges to be able to write to directories or send signals
to processes running as another user.

4. Log output of scripts to a directory in "/tmp".

As a way of working out problems, send the output of any commands to
a log file in "/tmp". Ie., run your command as:

   os.system( "kill -s SIGUSR1 26199 >> /tmp/dummy.log 2>&1" )

This will allow you to see any errors. With the way that Apache works,
you might not otherwise see errors generated by a call to os.system()
until Apache is shutdown and certain buffers are flushed out.

Graham




More information about the Mod_python mailing list