check instace already running...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fabio Pliger

    #1

    check instace already running...

    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.


  • Sidharth Kuruvila

    #2
    Re: check instace already running...

    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.remo ve(lockfile))

    //Your code here

    On Apr 9, 2005 2:32 PM, Sidharth Kuruvila <sidharth.kuruv ila@gmail.com> wrote:[color=blue]
    > 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.remo ve(lockfile))
    >
    > //Your code here
    >
    > On Apr 9, 2005 2:01 PM, Fabio Pliger <fabio.pliger@s iavr.it> wrote:[color=green]
    > > 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
    > >[/color]
    >
    > --
    > http://blogs.applibase.net/sidharth
    >[/color]


    --

    Comment

    • Aldric L'Hernault

      #3
      Re: check instace already running...

      Sidharth Kuruvila a écrit :[color=blue]
      > 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.[/color]

      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.

      Comment

      • Fabio Pliger

        #4
        Re: check instace already running...

        "Aldric L'Hernault" <aldric.lhernau lt@free.fr.net^ W> ha scritto nel
        messaggio news:42590357$0 $28646$636a15ce @news.free.fr.. .[color=blue]
        > Sidharth Kuruvila a écrit :[color=green]
        > > 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.[/color]
        >
        > 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.[/color]


        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?



        Comment

        Working...