From f7538a63b57885a23483aa3d63ebc6d23060a9c7 Mon Sep 17 00:00:00 2001 From: Falldog Date: Fri, 5 Sep 2014 21:29:50 +0800 Subject: [PATCH] fix the issue : watch & unwatch the same folder on Windows may cause exception "Access Denied" should close the dir handle --- src/watchdog/observers/winapi.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/watchdog/observers/winapi.py b/src/watchdog/observers/winapi.py index ff99a5009..eb5f37299 100644 --- a/src/watchdog/observers/winapi.py +++ b/src/watchdog/observers/winapi.py @@ -281,8 +281,12 @@ def get_directory_handle(path): def close_directory_handle(handle): try: CancelIoEx(handle, None) # force ReadDirectoryChangesW to return + CloseHandle(handle) # close directory handle except WindowsError: - return + try: + CloseHandle(handle) # close directory handle + except: + return def read_directory_changes(handle, recursive):