A unique instance of Python GUI program

r0g aioe.org at technicalbloke.com
Thu Sep 18 06:35:36 CEST 2008

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.


More information about the Python-list mailing list