applicationinstance module

class applicationinstance.ApplicationInstance(pidFile, autoExit=True, flock=False)[source]

Bases: object

Class used to handle one application instance mechanism.

Parameters:
  • pidFile (str) – full path of file used to save pid and procname
  • autoExit (bool) – automatically call sys.exit if there is an other instance running
  • flock (bool) – use file-locks to make sure only one instance is checking at the same time
busy()[source]

Check if one application with this instance is currently running.

Returns:True if an other instance is currently running.
Return type:bool
check(autoExit=False)[source]

Check if the current application is already running

Parameters:autoExit (bool) – automatically call sys.exit if there is an other instance running
Returns:
True if this is the only application
instance
Return type:bool
exitApplication()[source]

Called when the single instance exit (remove pid file)

flockExclusiv()[source]

Create an exclusive lock to block a second instance while the first instance is starting.

flockUnlock()[source]

Remove the exclusive lock. Second instance can now continue but should find it self to be obsolete.

readPidFile()[source]

Read the pid and procname from the file

Returns:tuple of (pid(int), procname(str))
Return type:tuple
startApplication()[source]

Called when the single instance starts to save its pid