473,378 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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.
Jul 18 '05 #1
3 3647
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Amrik Singh | last post by:
HI folks can anyone help a newbie here. I would like to know how I can check if my software is already running. So that if the user click s on the shortcut to start the progam again it maximises...
6
by: Pierre-Yves | last post by:
Hello, I would like to prevent my perl program to be executed several times simultaneously (if the program is already running, I would like to display a message like "another instance of this...
4
by: Ravi | last post by:
Hi, I have a (stupid) question on why web service class needs an instance. Everybody knows its stateless then why cant it can be standardized that all methos in web service class should be static....
4
by: Nick Sinclair | last post by:
Hi all, I'm new to C. I have successfully written a small C program that acts as a "wrapper" around cgi scripts. These scripts perform admin tasks such as backing up etc. Obviously, The need...
4
by: Michael Passalacqua | last post by:
In VB.NET, how do you check to see if an instance of your application is already running? Michael Passalacqua Portland Community College CIS Faculty *** Sent via Developersdex...
4
by: TM | last post by:
Is there any way to check if another instance of my program is running if a user executes it ? I would like to warn the user if the program is already running to prevent multiple instances. ...
14
by: Alex K. | last post by:
Hi all I'd like to avoid starting the same c# application twice on the same computer. How do I check if it is already running? Thank you
1
by: keri | last post by:
Hi, I use the below for the user to view their outlook calendar Sub DisplayInbox() Dim myolApp As Outlook.Application Dim myNameSpace As Outlook.NameSpace Dim myFolder As Outlook.MAPIFolder...
9
by: fniles | last post by:
I am using VB.NET 2005. To check if the same program already run or not, I can use the following If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length MsgBox("Another...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.