From 80e1afc95893350e6e59230993e26376e279327c Mon Sep 17 00:00:00 2001 From: Sebastien Martini Date: Thu, 9 Sep 2010 10:45:50 +0200 Subject: Added new method WatchManager.close() to close inotify's file descriptor when needed (bug reported by jdw@research.att.com). --- python2/pyinotify.py | 12 ++++++++++++ python3/pyinotify.py | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/python2/pyinotify.py b/python2/pyinotify.py index e10aa83..d7fb8af 100755 --- a/python2/pyinotify.py +++ b/python2/pyinotify.py @@ -1607,6 +1607,18 @@ class WatchManager: err = 'Cannot initialize new instance of inotify%s' % strerrno() raise OSError(err) + def close(self): + """ + Close inotify's file descriptor, this action will also automatically + remove (i.e. stop watching) all its associated watch descriptors. + After a call to this method the WatchManager's instance become useless + and cannot be reused, a new instance must then be instanciated. It + makes sense to call this method in few situations for instance if + several independant WatchManager must be instanciated or if all watches + must be removed and no other watches need to be added. + """ + os.close(self._fd) + def get_fd(self): """ Return assigned inotify's file descriptor. diff --git a/python3/pyinotify.py b/python3/pyinotify.py index a2eda17..9a7afac 100755 --- a/python3/pyinotify.py +++ b/python3/pyinotify.py @@ -1555,6 +1555,18 @@ class WatchManager: err = 'Cannot initialize new instance of inotify Errno=%s' raise OSError(err % strerrno()) + def close(self): + """ + Close inotify's file descriptor, this action will also automatically + remove (i.e. stop watching) all its associated watch descriptors. + After a call to this method the WatchManager's instance become useless + and cannot be reused, a new instance must then be instanciated. It + makes sense to call this method in few situations for instance if + several independant WatchManager must be instanciated or if all watches + must be removed and no other watches need to be added. + """ + os.close(self._fd) + def get_fd(self): """ Return assigned inotify's file descriptor. -- cgit v1.2.1