comparison python-daemon-2.0.5/daemon/pidfile.py @ 33:7ceb967147c3

start xena with no gui add library files
author jingchunzhu <jingchunzhu@gmail.com>
date Wed, 22 Jul 2015 13:24:44 -0700
parents
children
comparison
equal deleted inserted replaced
32:63b1ba1e3424 33:7ceb967147c3
1 # -*- coding: utf-8 -*-
2
3 # daemon/pidfile.py
4 # Part of ‘python-daemon’, an implementation of PEP 3143.
5 #
6 # Copyright © 2008–2015 Ben Finney <ben+python@benfinney.id.au>
7 #
8 # This is free software: you may copy, modify, and/or distribute this work
9 # under the terms of the Apache License, version 2.0 as published by the
10 # Apache Software Foundation.
11 # No warranty expressed or implied. See the file ‘LICENSE.ASF-2’ for details.
12
13 """ Lockfile behaviour implemented via Unix PID files.
14 """
15
16 from __future__ import (absolute_import, unicode_literals)
17
18 from lockfile.pidlockfile import PIDLockFile
19
20
21 class TimeoutPIDLockFile(PIDLockFile, object):
22 """ Lockfile with default timeout, implemented as a Unix PID file.
23
24 This uses the ``PIDLockFile`` implementation, with the
25 following changes:
26
27 * The `acquire_timeout` parameter to the initialiser will be
28 used as the default `timeout` parameter for the `acquire`
29 method.
30
31 """
32
33 def __init__(self, path, acquire_timeout=None, *args, **kwargs):
34 """ Set up the parameters of a TimeoutPIDLockFile.
35
36 :param path: Filesystem path to the PID file.
37 :param acquire_timeout: Value to use by default for the
38 `acquire` call.
39 :return: ``None``.
40
41 """
42 self.acquire_timeout = acquire_timeout
43 super(TimeoutPIDLockFile, self).__init__(path, *args, **kwargs)
44
45 def acquire(self, timeout=None, *args, **kwargs):
46 """ Acquire the lock.
47
48 :param timeout: Specifies the timeout; see below for valid
49 values.
50 :return: ``None``.
51
52 The `timeout` defaults to the value set during
53 initialisation with the `acquire_timeout` parameter. It is
54 passed to `PIDLockFile.acquire`; see that method for
55 details.
56
57 """
58 if timeout is None:
59 timeout = self.acquire_timeout
60 super(TimeoutPIDLockFile, self).acquire(timeout, *args, **kwargs)
61
62
63 # Local variables:
64 # coding: utf-8
65 # mode: python
66 # End:
67 # vim: fileencoding=utf-8 filetype=python :