474,059 Members | 2,868 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A unique instance of Python GUI program

Hello everyone,

This may not be a Python specific challenge.
I have a GUI program written in Python + Tkinter.
It works very well.

Now, I would like to start it from a shell script.
As my GUI program includes a server, it should not have more than one
instance.
Is there any easy way to check if another instance of the program is
already running.

I vaguely remember that Windows programming provides a way to check.

A platform independent approach would be nice but a solution for X is
sufficient for my application.

Any comments will be greatly appreciated.

Best regards,
Aki Niimura
Sep 16 '08 #1
8 1996
akineko wrote:
This may not be a Python specific challenge.
I have a GUI program written in Python + Tkinter.
It works very well.

Now, I would like to start it from a shell script.
As my GUI program includes a server, it should not have more than one
instance.
Is there any easy way to check if another instance of the program is
already running.

I vaguely remember that Windows programming provides a way to check.

A platform independent approach would be nice but a solution for X is
sufficient for my application.
I swear this question's been asked twice this month already.
Is there a convention going on of one-instance-only application writers?

Have a look at:

http://mail.python.org/pipermail/pyt...st/505958.html

http://mail.python.org/pipermail/pyt...st/505992.html

http://mail.python.org/pipermail/pyt...st/505850.html

or just search the mailing lists for various previous
discussions:

http://www.google.com/search?q=site%...ingle+instance

(or similar queries)

TJG
Sep 16 '08 #2
akineko schrieb:
Hello everyone,

This may not be a Python specific challenge.
I have a GUI program written in Python + Tkinter.
It works very well.

Now, I would like to start it from a shell script.
As my GUI program includes a server, it should not have more than one
instance.
Is there any easy way to check if another instance of the program is
already running.

I vaguely remember that Windows programming provides a way to check.
On windows a mutex does the job, see CreateMutex in the windows api.
A platform independent approach would be nice but a solution for X is
sufficient for my application.
I'm not familiar with Tkinter - you might want to check if it supports
mutexes. Though I'm not sure if mutexes are cross-process (system wide)
on all platforms.

Regards
Georg

Sep 16 '08 #3
akineko wrote:
Hello everyone,

This may not be a Python specific challenge.
I have a GUI program written in Python + Tkinter.
It works very well.

Now, I would like to start it from a shell script.
As my GUI program includes a server, it should not have more than one
instance.
Is there any easy way to check if another instance of the program is
already running.

I vaguely remember that Windows programming provides a way to check.

A platform independent approach would be nice but a solution for X is
sufficient for my application.

Any comments will be greatly appreciated.

Best regards,
Aki Niimura
Here is a recipe:

http://code.activestate.com/recipes/474070/

-Larry
Sep 16 '08 #4
On Sep 16, 1:58*am, Tim Golden <m...@timgolden .me.ukwrote:
I swear this question's been asked twice this month already.

Thank you very much for many pointers.
I'm awfully sorry for posting something that is already answered in
the past.
I tried to find answers to my problem using "unique instance" as a
keyword.
I guess I should have used "single instance" or "one instance",
instead.
I will try to be more careful before posting.

Thank you.
Aki Niimura
Sep 16 '08 #5
akineko wrote:
On Sep 16, 1:58 am, Tim Golden <m...@timgolden .me.ukwrote:
>I swear this question's been asked twice this month already.


Thank you very much for many pointers.
I'm awfully sorry for posting something that is already answered in
the past.
I was more amused than annoyed. Don't let my tone put
you off. In any case, searching is all too often a
question of knowing what the answer is so you can
search for it!

TJG
Sep 17 '08 #6
Again, thank you for many postings to my question.
I have reviewed solutions provided.
Well, I like the named Mutex solution under Windows.
That is a clean and straight-forward approach to the challenge.
(I cannot believe that I'm saying good thing about Windows ;-) )

Unfortunately, I'm living in Unix realm ;-)

None of solutions for Unix are appealing to me.
But they must be "the" solution for the challenge as well-established
software uses those solutions.

Now, I'm wondering.
As my program is a GUI (Tkinter) software.
Is it possible to set a known value to X11 or Tk property through
Tkinter so that another instance of the program can check if such
property is set?

Of course, I know this scheme has a flaw. If one instance uses another
logical display, then such property is probably not shared.
But for my usage, it is logically possible but not likely.

I checked my Tkinter book and found the following function.
winfo_interps(d isplayof=0)

This returns a list of all Tk-based applications currently running on
the display.

When I tried, I got the following:
>>root.winfo_in terps()
('tk #3', 'tk #2', 'tk')

But I couldn't find a way to set a specific name to the Tcl
interpreter.

As I'm not an expert of Tcl/Tk and X11, I probably overlooked other
functions that may do what I need.

Any comments, suggestions on this?
Maybe this can provide a platform independent way to ensure that only
single instance is running.

Thank you for your attention.

Best reagrds,
Aki Niimura
Sep 18 '08 #7
r0g
akineko wrote:
Again, thank you for many postings to my question.
I have reviewed solutions provided.
Well, I like the named Mutex solution under Windows.
That is a clean and straight-forward approach to the challenge.
(I cannot believe that I'm saying good thing about Windows ;-) )

Unfortunately, I'm living in Unix realm ;-)

None of solutions for Unix are appealing to me.
But they must be "the" solution for the challenge as well-established
software uses those solutions.

Now, I'm wondering.
As my program is a GUI (Tkinter) software.
Is it possible to set a known value to X11 or Tk property through
Tkinter so that another instance of the program can check if such
property is set?

Of course, I know this scheme has a flaw. If one instance uses another
logical display, then such property is probably not shared.
But for my usage, it is logically possible but not likely.

I checked my Tkinter book and found the following function.
winfo_interps(d isplayof=0)

This returns a list of all Tk-based applications currently running on
the display.

When I tried, I got the following:
>>>root.winfo_i nterps()
('tk #3', 'tk #2', 'tk')

But I couldn't find a way to set a specific name to the Tcl
interpreter.

As I'm not an expert of Tcl/Tk and X11, I probably overlooked other
functions that may do what I need.

Any comments, suggestions on this?
Maybe this can provide a platform independent way to ensure that only
single instance is running.

Thank you for your attention.

Best reagrds,
Aki Niimura

I know it's a hack but couldn't you just open a specific UDP socket and
leave it dangling til your program exits, then if a new instance can't
open that same socket it can gracefully abort? If your program dies the
socket will be freed up again by the OS yes?

Just a thought.

Roger.
Sep 18 '08 #8
On 2008-09-16, akineko <ak*****@gmail. comwrote:
This may not be a Python specific challenge. I have a GUI
program written in Python + Tkinter. It works very well.

Now, I would like to start it from a shell script. As my GUI
program includes a server, it should not have more than one
instance. Is there any easy way to check if another instance
of the program is already running.

I vaguely remember that Windows programming provides a way to
check.
On unix the solution is usually a lockfile placed in a
predefined location. Other people use a socket, but that's a
bit more susceptible to namespace collisions with unrelated
programs.
A platform independent approach would be nice but a solution
for X is sufficient for my application.
I don't see what X has to do with it.
Any comments will be greatly appreciated.
This question is asked and answered about once a week, and I'm
always surprised at how frequently it comes up. I've been
doing sw development for decades and apart from Unix system
daemons, I don't remember ever needing to prevent multiple
instances of an application from running. Can somebody lend me
a clue as to why this question comes up so often? There can't
be that many people writing Unix daemons in Python (and if they
were, they'd probably already know about lockfiles).

Just curious...

--
Grant Edwards grante Yow! Is something VIOLENT
at going to happen to a
visi.com GARBAGE CAN?
Sep 18 '08 #9

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

Similar topics

12
2734
by: Russell E. Owen | last post by:
I have several situations in my code where I want a unique identifier for a method of some object (I think this is called a bound method). I want this id to be both unique to that method and also stable (so I can regenerate it later if necessary). I thought the id function was the obvious choice, but it doesn't seem to work. The id of two different methods of the same object seems to be the same, and it may not be stable either. For...
10
4284
by: Jerry LeVan | last post by:
Hi, I am futzing around with Andrew Stuarts "Catchmail" program that stores emails into a postgresql database. I want to avoid inserting the same email more than once... (pieces of the email actually get emplaced into several tables). Is the "Message-ID" header field a globally unique identifer?
2
1414
by: Peter Oliphant | last post by:
Sometimes it's hard to get straight when passing or storing or returning an instance of a class whether you are still dealing with the original object or a copy. For example, the '=' operator used on pointers to two instance of a class can be overloaded to return the pointer to the target instance or a pointer to a copy of the target instance. When passing an instance of a class it can be done so the method will manipulate the instance...
10
5138
by: John M. Gabriele | last post by:
The following short program fails: ----------------------- code ------------------------ #!/usr/bin/python class Parent( object ): def __init__( self ): self.x = 9 print "Inside Parent.__init__()"
5
2676
by: EP | last post by:
This inquiry may either turn out to be about the suitability of the SHA-1 (160 bit digest) for file identification, the sha function in Python ... or about some error in my script. Any insight appreciated in advance. I am trying to reduce duplicate files in storage at home - I have a large number files (e.g. MP3s) which have been stored on disk multiple times under different names or on different paths. The using applications will...
4
1332
by: Gre7g Luterman | last post by:
I suppose I was lulled into complacency by how Python makes so many things look like classes, but I'm starting to realize that they're not, are they? I'm writing a C program which handles Python objects in different ways based on their type. I do a PyInstance_Check(PyObj) to determine if the PyObj is an instance, but it is returning 0 on a lot of stuff that I thought would be an instance. So I did the following simple test on three things...
1
2340
by: Jim Langston | last post by:
Windows. Situation: Using a Python program called OpenRPG. I have a program that displays form data (a character sheet) in C++. I am able in the C++ program to build a string and copy it into the clipboard, then paste it into the input in the running Python program. I would like to somehow automate this, that is, have the python instance communicate with the C++ instance and vice versa. I'm still trying to think of a way to do this. ...
2
4474
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for statistical purposes. I've been using Here's the situation: I have two main tables:
11
7205
by: breal | last post by:
I have three lists... for instance a = ; b = ; c = ; I want to take those and end up with all of the combinations they create like the following lists
0
10378
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11637
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
12091
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
11168
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
10358
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...
0
7901
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();...
0
6686
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6892
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
4002
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.