check instace already running...

Discussion in 'Python' started by Fabio Pliger, Apr 9, 2005.

  1. Fabio Pliger

    Fabio Pliger Guest

    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.
     
    Fabio Pliger, Apr 9, 2005
    #1
    1. Advertising

  2. 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:eek:s.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(lambda:eek:s.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
     
    Sidharth Kuruvila, Apr 9, 2005
    #2
    1. Advertising

  3. 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.
     
    Aldric L'Hernault, Apr 10, 2005
    #3
  4. Fabio Pliger

    Fabio Pliger Guest

    "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?
     
    Fabio Pliger, Apr 10, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dino Buljubasic
    Replies:
    4
    Views:
    18,533
    Roedy Green
    Sep 23, 2005
  2. flack
    Replies:
    15
    Views:
    6,790
    Gordon Beaton
    Mar 31, 2006
  3. Nick Sinclair

    How to check for already running program?

    Nick Sinclair, Jul 1, 2005, in forum: C Programming
    Replies:
    4
    Views:
    439
    Nick Sinclair
    Jul 4, 2005
  4. MikeTI

    Check form already open in browser

    MikeTI, Sep 5, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    329
    Patrice
    Sep 5, 2009
  5. Stefan Salewski
    Replies:
    5
    Views:
    135
    Jeremy Bopp
    Oct 7, 2010
Loading...

Share This Page