'Closes the inotify instance and removes all associated watches.'

def close(self):

    with self._lock:
        if (self._path in self._wd_for_path):
            wd = self._wd_for_path[self._path]
            inotify_rm_watch(self._inotify_fd, wd)
        os.close(self._inotify_fd)
