summaryrefslogtreecommitdiff
path: root/python3
diff options
context:
space:
mode:
authorSebastien Martini <seb@dbzteam.org>2010-09-15 01:08:07 +0200
committerSebastien Martini <seb@dbzteam.org>2010-09-15 01:08:07 +0200
commit909f985842fcae8a45d9591017112186e68a723d (patch)
tree7ef6a19285efd6100e88190a7fa6595922dfc5f9 /python3
parent155e2f5d0dfeff210198856b2b03d53d8e810c52 (diff)
downloadpyinotify-909f985842fcae8a45d9591017112186e68a723d.tar.gz
Optionally no pid file is written (pid_file=False) when notifier.loop
with daemonize=True is called.
Diffstat (limited to 'python3')
-rwxr-xr-xpython3/pyinotify.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/python3/pyinotify.py b/python3/pyinotify.py
index 84fa17a..acee931 100755
--- a/python3/pyinotify.py
+++ b/python3/pyinotify.py
@@ -1163,7 +1163,9 @@ class Notifier:
def __daemonize(self, pid_file=None, stdin=os.devnull, stdout=os.devnull,
stderr=os.devnull):
"""
- pid_file: file to which the pid will be written.
+ pid_file: file where the pid will be written. If pid_file=None the pid
+ is written to /var/run/<sys.argv[0]|pyinotify>.pid, if
+ pid_file=False no pid_file is written.
stdin, stdout, stderr: files associated to common streams.
"""
if pid_file is None:
@@ -1171,7 +1173,7 @@ class Notifier:
basename = os.path.basename(sys.argv[0]) or 'pyinotify'
pid_file = os.path.join(dirname, basename + '.pid')
- if os.path.lexists(pid_file):
+ if pid_file != False and os.path.lexists(pid_file):
err = 'Cannot daemonize: pid file %s already exists.' % pid_file
raise NotifierError(err)
@@ -1205,13 +1207,14 @@ class Notifier:
fork_daemon()
# Write pid
- flags = os.O_WRONLY|os.O_CREAT|os.O_NOFOLLOW|os.O_EXCL
- fd_pid = os.open(pid_file, flags, 0o0600)
- os.write(fd_pid, bytes(str(os.getpid()) + '\n',
- locale.getpreferredencoding()))
- os.close(fd_pid)
-
- atexit.register(lambda : os.unlink(pid_file))
+ if pid_file != False:
+ flags = os.O_WRONLY|os.O_CREAT|os.O_NOFOLLOW|os.O_EXCL
+ fd_pid = os.open(pid_file, flags, 0o0600)
+ os.write(fd_pid, bytes(str(os.getpid()) + '\n',
+ locale.getpreferredencoding()))
+ os.close(fd_pid)
+ # Register unlink function
+ atexit.register(lambda : os.unlink(pid_file))
def _sleep(self, ref_time):
@@ -1241,7 +1244,12 @@ class Notifier:
@type daemonize: boolean
@param args: Optional and relevant only if daemonize is True. Remaining
keyworded arguments are directly passed to daemonize see
- __daemonize() method.
+ __daemonize() method. If pid_file=None or is set to a
+ pathname the caller must ensure the file does not exist
+ before this method is called otherwise an exception
+ pyinotify.NotifierError will be raised. If pid_file=False
+ it is still daemonized but the pid is not written in any
+ file.
@type args: various
"""
if daemonize: