473,769 Members | 6,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Allowing only one instance of a script?

Ali
Hi,

I have a script which I double-click to run. If i double-click it
again, it will launch another instance of the script.

Is there a way to allow only one instance of a script, so that if
another instance of the script is launched, it will just return with an
error.

Thanks

Regards,
Ali

Jul 19 '05 #1
4 2891
Am Wed, 22 Jun 2005 23:49:21 -0700 schrieb Ali:
Hi,

I have a script which I double-click to run. If i double-click it
again, it will launch another instance of the script.

Is there a way to allow only one instance of a script, so that if
another instance of the script is launched, it will just return with an
error.


Hi,

Create a file which contains the PID (process ID) of
the current process in a directory. If the file
already exists, the file is running.

If your script dies without removing the pid-file, you
need to look during the start if the PID which is in the
file is sill alive.

There is a small race condition between os.path.exists( )
and writing the file. If you want to be 100% sure you need
to use file locking.

HTH,
Thomas
--
Thomas Güttler, http://www.thomas-guettler.de/
Jul 19 '05 #2
On 2005-06-23, Thomas Guettler <gu*****@thom as-guettler.de> wrote:
Create a file which contains the PID (process ID) of
the current process in a directory. If the file
already exists, the file is running.
That's how it's usually done.
If your script dies without removing the pid-file, you need to
look during the start if the PID which is in the file is sill
alive.
There is a small race condition between os.path.exists( )
and writing the file.
That's why it's pointless to call os.path.exists( ).
If you want to be 100% sure you need to use file locking.


I've never seen it done that way.

The standard method is to use open() with flags O_CREAT|O_EXCL.
If the open() is sucessful, then you have the lock. If it
fails, somebody else already has the lock.

Another method is to create a temp file containing the PID and
then call link() to rename it.

Both open() and link() are atomic operations, so there's no
race condition.

--
Grant Edwards grante Yow! I don't know WHY I
at said that... I think it
visi.com came from the FILLINGS inmy
read molars...
Jul 19 '05 #3
In article <11************ *@corp.supernew s.com>,
Grant Edwards <gr****@visi.co m> wrote:

Both open() and link() are atomic operations, so there's no
race condition.


....unless you're running under NFS.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

f u cn rd ths, u cn gt a gd jb n nx prgrmmng.
Jul 19 '05 #4
On 2005-06-23, Aahz <aa**@pythoncra ft.com> wrote:
In article <11************ *@corp.supernew s.com>,
Grant Edwards <gr****@visi.co m> wrote:

Both open() and link() are atomic operations, so there's no
race condition.


...unless you're running under NFS.


I think read somewhere than NFS 3 handles the open with
CREAT+EXCL in an atomic manner (older versions didn't). I don't
know about link.

--
Grant Edwards grante Yow! Will it improve my
at CASH FLOW?
visi.com
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2452
by: Leif K-Brooks | last post by:
I'm writing a site with mod_python which will have, among other things, forums. I want to allow users to use some HTML (<em>, <strong>, <p>, etc.) on the forums, but I don't want to allow bad elements and attributes (onclick, <script>, etc.). I would also like to do basic validation (no overlapping elements like <strong><em>foo</em></strong>, no missing end tags). I'm not asking anyone to write a script for me, but does anyone have general...
8
3372
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to process this .txt file. Goal: I am working on a vba script to:
3
11301
by: traceable1 | last post by:
Is there a way I can set up a SQL script to run when the instance starts up? SQL Server 2005 SP2 thanks!
4
1323
by: cj | last post by:
I've often used methods exposed by software purchased for other uses to automate tasks. For instance back in the late 90's I found the terminal emulation package the company exposed methods that allowed me to write a VB program that could use that terminal emulation package to connect to, read, and enter data on the company's mainframes. I think this was called OLE? Well now I'm on the other end of the picture and I need to write into a...
0
9589
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10050
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.