Fredrik Lundh wrote:
Hari Sekhon wrote: How exactly do you check that the pid is still active in python? Is there a library or something that will allow me to manipulate system processes and listings etc the way everybody does in unix shells.... I'm a huge fan of shell so I've done my own thing which leans on shell as follows: import sys,commands,os scriptpath = sys.argv[0] scriptname = os.path.basename(scriptpath) number_procs=commands.getstatusoutput('ps -ef|grep %s|grep -v grep|wc -l' % scriptpath) if number_procs > 1: print "There appears to be another %s process running." % scriptname print "Please do not run more than one instance of this program" print "Quitting for safety..." sys.exit(200) This works nicely for me. You might also want to add a bit of discrimination to the script (something along the lines of "get a decent os"...since this won't work on windows) import platform if platform.system() != 'Linux': print "Sorry but this program can only be run on Linux" sys.exit(201) #todo: should do a bit extra for our bsd cousins here.... Let me know if you think you have a better way. Please provide a code snippet if so. -h |
-- http://mail.python.org/mailman/listinfo/python-list
