PID File Handling

musicdb.lib.pidfile.CheckPIDFile(pidfile)[source]

This function checks whether a PID file exists or not. If the file pidfile does exist its content, a process ID, gets read and returned. If the file does not exist, None gets returned.

Parameters

pidfile (str) – Absolute path to a PID file

Returns

The stored process ID if the file exists, otherwise None. The PID is of type int.

Example

server = CheckPIDFile("/tmp/server.pid"):
if server:
    print("Server has PID %d."%(server))
else:
    print("There is no server running!")
musicdb.lib.pidfile.CreatePIDFile(pidfile, pid=None)[source]

This function creates a PID file. If the process ID is not given via pid-argument, the current PID will be determined.

The PID gets written into the file addressed by the pidfile parameter. If the file does not exist (it should not) a new one will be created. The path shall be absolute!

Parameters
  • pidfile (str) – absolute path for the PID file.

  • pid – The Process ID. If None the PID gets determined.

Returns

None

Example

CreatePIDFile("/tmp/test.pid")
CreatePIDFile("/tmp/fake.pid", 1000)
musicdb.lib.pidfile.DeletePIDFile(pidfile)[source]

This function removes the PID file (or any other file) addressed by an absolute path in pidfile.

Parameters

pidfile (str) – Absolute path of a file to remove

Returns

None