By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,592 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,592 IT Pros & Developers. It's quick & easy.

check instace already running...

P: n/a
Hi,
is it possibile, in python, to check for an already running instance of an
application?
My problem is that, if my program i running and the user relaunch it, i
don't want to open a new instance and have to instances of the same program
running togheter...
Can someone help me on this?
Fabio P.
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I haven't tested this. There is probably a better way of doing this
looking at process information. I use a lock file to mark that the
program is already running. The problem is that for an abrupt shutdown
the file might not be removed.

import atexit
if os.path.exists(lockfile):
print "there is an instance already running"
else:
file(lockfile, "w").close()
atexit.register(lambda:os.remove(lockfile))

//Your code here

On Apr 9, 2005 2:32 PM, Sidharth Kuruvila <si***************@gmail.com> wrote:
I haven't tested this. There is probably a better way of doing this
looking at process information. I use a lock file to mark that the
program is already running. The problem is that for an abrupt shutdown
the file might not be removed.

import atexit
if os.path.exists(lockfile):
print "there is an instance already running"
else:
file(lockfile, "w").close()
atexit.register(lambda:os.remove(lockfile))

//Your code here

On Apr 9, 2005 2:01 PM, Fabio Pliger <fa**********@siavr.it> wrote:
Hi,
is it possibile, in python, to check for an already running instance of an
application?
My problem is that, if my program i running and the user relaunch it, i
don't want to open a new instance and have to instances of the same program
running togheter...
Can someone help me on this?
Fabio P.

--
http://mail.python.org/mailman/listinfo/python-list


--
http://blogs.applibase.net/sidharth

--
http://blogs.applibase.net/sidharth
Jul 18 '05 #2

P: n/a
Sidharth Kuruvila a écrit :
I haven't tested this. There is probably a better way of doing this
looking at process information. I use a lock file to mark that the
program is already running. The problem is that for an abrupt shutdown
the file might not be removed.


To enhance your check, just write the PID into the file.
On startup, if file exists, you may check that the process
who has written it is still alive.

Aldric L.
Jul 18 '05 #3

P: n/a
"Aldric L'Hernault" <al**************@free.fr.net^W> ha scritto nel
messaggio news:42***********************@news.free.fr...
Sidharth Kuruvila a écrit :
I haven't tested this. There is probably a better way of doing this
looking at process information. I use a lock file to mark that the
program is already running. The problem is that for an abrupt shutdown
the file might not be removed.


To enhance your check, just write the PID into the file.
On startup, if file exists, you may check that the process
who has written it is still alive.

Aldric L.

Yeah, but how can i retrieve my PID number?And how do i check if the process
who has written the file is still alive?If there a way to have the list of
the precesses running?

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.