Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes EventDebouncer not producing events #998

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/watchdog/utils/event_debouncer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import time
import threading

from watchdog.utils import BaseThread
Expand Down Expand Up @@ -36,21 +37,27 @@ def stop(self):
super().stop()
self._cond.notify()

def time_to_flush(self, started) -> bool:
BoboTiG marked this conversation as resolved.
Show resolved Hide resolved
return time.monotonic() - started > self.debounce_interval_seconds

def run(self):
with self._cond:
while True:
# Wait for first event (or shutdown).
self._cond.wait()

while self.should_keep_running():
started = time.monotonic()
if self.debounce_interval_seconds:
# Wait for additional events (or shutdown) until the debounce interval passes.
while self.should_keep_running():
if not self._cond.wait(timeout=self.debounce_interval_seconds):
timed_out = not self._cond.wait(
timeout=self.debounce_interval_seconds
)
if timed_out or self.time_to_flush(started):
break

if not self.should_keep_running():
break
else:
self._cond.wait()

events = self._events
self._events = []
self.events_callback(events)

# send any events before leaving
if self._events:
self.events_callback(events)
Loading