473,563 Members | 2,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

//Your code here

On Apr 9, 2005 2:01 PM, Fabio Pliger <fa**********@s iavr.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
9636
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 the already running program. tia Amrik
6
10507
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 program is already running, please try again in a couple of minutes). For doing this, I guess I have to check the running processes... but I don't...
4
1461
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. For eg I create an instance websrv. I have 2(set/get) methods and a private variable 'name'. websrv.setName("Hello"); and in next line if I call...
4
5992
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 for the "wrapper" was to get the scripts to run with "root" privileges. So far so good. I simply create a "URL shortcut" that some staff can...
4
14784
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 http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
4
4509
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. Thanks -- Tony
14
9638
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
2818
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 Set myolApp = CreateObject("Outlook.Application") Set myNameSpace = myolApp.GetNamespace("MAPI")
9
4128
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 instance of " & Process.GetCurrentProcess.ProcessName & " is already running !") End End If I am wondering if I can check the same thing for a thread.
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.