applicationinstance module
This module holds the ApplicationInstance class, used to handle the one application instance mechanism
- class applicationinstance.ApplicationInstance(pidFile, autoExit=True, flock=False)[source]
Bases:
object
Class used to handle one application instance mechanism.
- Parameters:
- busy()[source]
Check if one application with this instance is currently running.
- Returns:
True
if an other instance is currently running.- Return type:
- flockExclusiv()[source]
Create an exclusive advisory file lock named <PID file>.flock to block the creation of a second instance while the first instance is still in the process of starting (but has not yet completely started).
The purpose is to make 1. the check if the PID lock file already exists 2. and the subsequent creation of the PID lock file an atomic operation by using a blocking “flock” file lock on a second file to avoid that two or more processes check for an existing PID lock file, find none and create a new one (so that only the last creator wins).
Dev notes:
buhtz (2023-09): Not sure but just log an ERROR without doing anything else is IMHO not enough. aryoda (2023-12): It seems the purpose of this additional lock file using an exclusive lock is to block the other process to continue until this exclusive lock is released (= serialize execution). Therefore advisory locks are used via fcntl.flock (see: man 2 fcntl)
- flockUnlock()[source]
Remove the exclusive lock. Second instance can now continue but should find it self to be obsolete.