def _remove_watch_for_path(self, path):
# Must be called with _inotify_fd_lock held.
logging.debug('_remove_watch_for_path(%r)', path)
wd = self._directory_to_watch_descriptor[path]
if _libc.inotify_rm_watch(self._inotify_fd, wd) < 0:
# If the directory is deleted then the watch will removed automatically
# and inotify_rm_watch will fail. Just log the error.
logging.debug('inotify_rm_watch failed for %r: %d [%r]',
path,
ctypes.get_errno(),
errno.errorcode[ctypes.get_errno()])
parent_path = os.path.dirname(path)
if parent_path in self._directory_to_subdirs:
self._directory_to_subdirs[parent_path].remove(path)
# _directory_to_subdirs must be copied because it is mutated in the
# recursive call.
for subdir in frozenset(self._directory_to_subdirs[path]):
self._remove_watch_for_path(subdir)
del self._watch_to_directory[wd]
del self._directory_to_watch_descriptor[path]
del self._directory_to_subdirs[path]
inotify_file_watcher.py 文件源码
python
阅读 39
收藏 0
点赞 0
评论 0
评论列表
文章目录