how to keep one instance???

Jeff Epler jepler at unpythonic.net
Tue May 18 08:46:29 EDT 2004


I'm not sure how Windows applications typically do this, in low-level
terms.

The answer, in general terms, would be that you need to have a way for a
new instance of your app to communicate with an existing one.  When the
user opens a file, the application starts by finding whether another
copy of the application has the document open, and if so that window is
just raised to the top and given focus.  Otherwise, the document is
actually opened.  You can expand this a little bit, so that if the
document was not yet open it's still opened in the first copy of the
application (but in a different window).

In Tk, the "send" command can be used to implement inter-application
communication.  Using the BLT package, "send" works on Windows as well
as Unix.  I've never used send for this purpose, though, and I'm not
even sure whether an interface to it is provided by Tkinter.  Other
widget toolkits might provide other methods, and there may be a single
method that you're supposed to use in a win32 application that I don't
know about.

Note that there are often race conditions here---if two copies of the
application start nearly simultaneously, both may detect that no
other copy of the app exists.  If someone wants to tell me the way to
get this right in the context of Unix/X11, please speak up!

Jeff




More information about the Python-list mailing list