From 7da6df4a4f7d99ef03445ecd3b738a535d9315f6 Mon Sep 17 00:00:00 2001 From: Sebastien Martini Date: Thu, 4 Jun 2015 15:23:17 +0200 Subject: Only close a valid file descriptor Idea contributed by @blueyed Close #93 --- python2/pyinotify.py | 7 +++++-- python3/pyinotify.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/python2/pyinotify.py b/python2/pyinotify.py index e1b93c6..679e141 100755 --- a/python2/pyinotify.py +++ b/python2/pyinotify.py @@ -1405,9 +1405,12 @@ class Notifier: Close inotify's instance (close its file descriptor). It destroys all existing watches, pending events,... This method is automatically called at the end of loop(). + Afterward it is invalid to access this instance. """ - self._pollobj.unregister(self._fd) - os.close(self._fd) + if self._fd is not None: + self._pollobj.unregister(self._fd) + os.close(self._fd) + self._fd = None self._sys_proc_fun = None diff --git a/python3/pyinotify.py b/python3/pyinotify.py index 23fae15..9fb815e 100755 --- a/python3/pyinotify.py +++ b/python3/pyinotify.py @@ -1391,9 +1391,12 @@ class Notifier: Close inotify's instance (close its file descriptor). It destroys all existing watches, pending events,... This method is automatically called at the end of loop(). + Afterward it is invalid to access this instance. """ - self._pollobj.unregister(self._fd) - os.close(self._fd) + if self._fd is not None: + self._pollobj.unregister(self._fd) + os.close(self._fd) + self._fd = None self._sys_proc_fun = None -- cgit v1.2.1