30 with self.
_open()
as pid_file:
35 with self.
_open()
as pid_file:
36 pid = self.
_read(pid_file)
37 if pid
is not None and self.
ping_proc(pid):
42 with self.
_open()
as pid_file:
54 if e.errno != errno.ESRCH:
60 for attempt
in range(5):
63 pid_fd = os.open(self.
path, os.O_RDWR | os.O_CREAT)
64 fcntl.flock(pid_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
66 if pid_fd
is not None:
68 if e.errno != errno.EWOULDBLOCK:
78 return os.fdopen(pid_fd,
'w+t')
80 def _read(self, pid_file):
83 raw = pid_file.read(1024)
86 except (IOError, ValueError)
as e:
90 def _write(self, pid_file):
93 pid_file.write(
'{}\n'.
format(os.getpid()))
98 def _ensure_owning(self, pid_file):
99 pid = self.
_read(pid_file)
100 if pid != os.getpid():
def _write(self, pid_file)
def _ensure_owning(self, pid_file)
def _read(self, pid_file)