Communication between a Python process and a Python cgi script

Donn Cave donn at u.washington.edu
Thu Apr 11 16:32:26 EDT 2002


Quoth Joonas Paalasmaa <joonas at olen.to>:
| I have a Python program started by root that does some magic stuff
| every 10 minutes. So the program in an infinite loop of sleep, do stuff,
| sleep, do stuff... How can I make a cgi-script to end the process's
| sleep phase and make it to "do stuff" immediately. I tried signals, but
| it is propably too risky because the process is run as root. Any
| suggestions?

You could try a named pipe -
$ mkfifo /tmp/fifo
$ cat /tmp/ptest
pipe = open('/tmp/fifo', 'r')
while 1:
    ping = pipe.read()
    print 'ping', repr(ping)
$ python /tmp/ptest &
$ echo junk > /tmp/fifo
ping 'junk\n'
$ echo junk > /tmp/fifo
ping 'junk\n'

Find a better name and place for the fifo, check that it will be
writable by the CGI process.  Consider security issues, who will
be able to do this - might be no compromise, yet you could have
a "denial of service" kind of attack.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list