application-development – How to Force Only One Instance of an Application

application-developmentindicatorpythonquickly

I am developing a program using quickly. I am using an indicator which can hide/show the main window.

But when I launch the application from the launcher it starts a new instance of that application (so an additional indicator will be shown). Rather than just showing the main window of the previous running app.

What's the usual way of forcing only one indicator?

Best Answer

First, make sure you have a good reason to do this. People expect applications to work as you describe in your post. Even though you personally might not like it.

But, to answer your question, one of the easiest ways to do it is by making a file (for example in the configuration directory) at startup, which you remove when your application exits. Before starting the application, you check in your code if another instance is already active, and if so, you exit directly. If you also want to focus the active application, you need a way to do inter process communication. For example via a socket. See http://docs.python.org/library/ipc.html for more info.