How to ensure just one instance of daemon?

Ben Finney ben+python at benfinney.id.au
Fri Aug 1 02:35:59 UTC 2014


On 27-Feb-2013, Chris Johnson wrote:
> Now what I am seeing is, multiple copies of my daemon are happy to run
> concurrently -- I expected to never have >1 instance running.

This is one of the main purposes of using a lockfile. They're not
specific to daemons, but your need is common: on start-up, the daemon
will exit if the lockfile already exists, and will create it
otherwise.

> Can you offer any advice?

The DaemonContext can be created specifying a lockfile context
manager, and will enter/exit the context when the daemon opens/closes.
Ensure that context manager tests for the lockfile and raises an
exception if it already exists.

This is the purpose of the ‘lockfile’ library. Use version 0.8
<URL:https://pypi.python.org/pypi/lockfile/0.8> which is the latest
version supported by ‘python-daemon’.

Or you can implement a different lockfile class to have your specific
desired behaviour.

-- 
 \      “Every man would like to be God, if it were possible; some few |
  `\          find it difficult to admit the impossibility.” —Bertrand |
_o__)                    Russell, _Power: A New Social Analysis_, 1938 |
Ben Finney <ben at benfinney.id.au>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/python-daemon-devel/attachments/20140801/978c4bc4/attachment.sig>


More information about the python-daemon-devel mailing list