473,474 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Create 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 1950
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(displayof=0)

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

When I tried, I got the following:
>>root.winfo_interps()
('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(displayof=0)

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

When I tried, I got the following:
>>>root.winfo_interps()
('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
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...
10
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...
2
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...
10
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...
5
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...
4
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...
1
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...
2
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...
11
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
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,...
0
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...
0
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,...
0
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
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...

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.