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

Report-errors in emitter #738

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/watchdog/events.py
Expand Up @@ -95,6 +95,7 @@
EVENT_TYPE_DELETED = 'deleted'
EVENT_TYPE_CREATED = 'created'
EVENT_TYPE_MODIFIED = 'modified'
EVENT_TYPE_ERROR = 'error'


class FileSystemEvent:
Expand Down Expand Up @@ -243,6 +244,22 @@ class DirMovedEvent(FileSystemMovedEvent):

is_directory = True

class FileObserverErrorEvent(FileSystemEvent):
"""File system event representing an error in the monitor."""
event_type = EVENT_TYPE_ERROR

def __init__(self, src_path, exception):
self._exception = exception
super(FileObserverErrorEvent, self).__init__(src_path)
Comment on lines +252 to +253
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._exception = exception
super(FileObserverErrorEvent, self).__init__(src_path)
super().__init__(src_path)
self._exception = exception


@property
def exception(self):
return self._exception

def __repr__(self):
return ("<%(class_name)s: exception=%(exception)r>"
) % (dict(class_name=self.__class__.__name__,
exception=repr(self.exception)))

class FileSystemEventHandler:
"""
Expand Down
6 changes: 5 additions & 1 deletion src/watchdog/observers/api.py
Expand Up @@ -19,6 +19,7 @@
import threading
from pathlib import Path

from watchdog.events import FileObserverErrorEvent
from watchdog.utils import BaseThread
from watchdog.utils.bricks import SkipRepeatsQueue

Expand Down Expand Up @@ -145,7 +146,10 @@ def queue_events(self, timeout):

def run(self):
while self.should_keep_running():
self.queue_events(self.timeout)
try:
self.queue_events(self.timeout)
except Exception as ex:
self.queue_event(FileObserverErrorEvent(self._watch.path, ex))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.queue_event(FileObserverErrorEvent(self._watch.path, ex))
self.queue_event(FileObserverErrorEvent(self._watch.path, ex))
# Prevent circular reference
ex = None
del ex



class EventDispatcher(BaseThread):
Expand Down