Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > check instace already running...

Reply
Thread Tools

check instace already running...

 
 
Fabio Pliger
Guest
Posts: n/a
 
      04-09-2005
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.


 
Reply With Quote
 
 
 
 
Sidharth Kuruvila
Guest
Posts: n/a
 
      04-09-2005
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(lambdas.remove(lockfile))

//Your code here

On Apr 9, 2005 2:32 PM, Sidharth Kuruvila <> 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(lambdas.remove(lockfile))
>
> //Your code here
>
> On Apr 9, 2005 2:01 PM, Fabio Pliger <> 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
 
Reply With Quote
 
 
 
 
Aldric L'Hernault
Guest
Posts: n/a
 
      04-10-2005
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.
 
Reply With Quote
 
Fabio Pliger
Guest
Posts: n/a
 
      04-10-2005
"Aldric L'Hernault" <^W> ha scritto nel
messaggio news:42590357$0$28646$...
> 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?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Missing @ for instace variable in class, but no error message Stefan Salewski Ruby 5 10-07-2010 03:17 AM
Check form already open in browser MikeTI ASP .Net 1 09-05-2009 01:05 PM
JNI: instace object C++ from Java flack Java 15 03-31-2006 12:12 PM
New to Java - How to check if a file is already open Dino Buljubasic Java 4 09-23-2005 02:47 AM
How to check for already running program? Nick Sinclair C Programming 4 07-04-2005 05:09 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57