Skip to content

Commit

Permalink
Since Python 3.13 threading.Thread has an internal _handle attribute …
Browse files Browse the repository at this point in the history
…which is overwritten by watchdog creating an exception.
  • Loading branch information
TobiasRzepka committed Jul 28, 2024
1 parent 4ffce94 commit 661d7e2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/watchdog/observers/read_directory_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class WindowsApiEmitter(EventEmitter):
def __init__(self, event_queue, watch, timeout=DEFAULT_EMITTER_TIMEOUT, event_filter=None):
super().__init__(event_queue, watch, timeout, event_filter)
self._lock = threading.Lock()
self._handle = None
self._dir_handle = None

def on_thread_start(self):
watch_path = self.watch.path
if os.path.isfile(watch_path):
watch_path = os.path.dirname(watch_path)
self._handle = get_directory_handle(watch_path)
self._dir_handle = get_directory_handle(watch_path)

if platform.python_implementation() == "PyPy":

Expand All @@ -65,11 +65,11 @@ def start(self):
sleep(0.01)

def on_thread_stop(self):
if self._handle:
close_directory_handle(self._handle)
if self._dir_handle:
close_directory_handle(self._dir_handle)

def _read_events(self):
return read_events(self._handle, self.watch.path, self.watch.is_recursive)
return read_events(self._dir_handle, self.watch.path, self.watch.is_recursive)

def queue_events(self, timeout):
winapi_events = self._read_events()
Expand Down

0 comments on commit 661d7e2

Please sign in to comment.