Sometimes it is desirable to only allow a single instance of an application to exist at any given time. The SingleInstanceChecker
class provides a way to detect if any instances of the application are already running. This recipe creates an App
class that uses the SingleInstanceChecker
to maintain only a single running instance of the application on the computer at one time, and also uses a simple IPC mechanism to allow any subsequent instances of the application to send a message to the original instance to tell it to open a new window.
Here, we will create an App
base class that ensures that only one instance of the process is running at a time, and supports a simple, socket-based inter-process communication mechanism to inform an already-running instance that a new one tried to start:
import wx import threading import socket import select class SingleInstApp(wx.App): """App baseclass that only allows a single instance to exist at a...