Search within running python scripts

faulkner faulkner612 at comcast.net
Mon Jul 24 16:01:21 EDT 2006


IPC via files, sockets, and shared memory are all readily available in
python.
the simplest way is to have the script write its pid to a certain file.

pidfn = '/tmp/hellowerld_ipc_pid'
if os.path.isfile(pidfn):
    f = file(pidfn)
    pid = f.read()
    f.close()
    if pid in os.popen('ps -A -o pid').read():
        print "another instance of me is running!"
    else:
        f = file(pidfn, 'w')
        f.write(str(os.getpid()))
        f.close()


gmax2006 wrote:
> Hi,
>
> Is it possible that a python script finds out whether another instance
> of it is currently running or not?
> 
> Thank you,
> Max




More information about the Python-list mailing list