Skip to content

Commit

Permalink
Patch from #788
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed May 7, 2021
1 parent 6dde6ed commit 8c4629c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
7 changes: 2 additions & 5 deletions src/watchdog/observers/fsevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ def __init__(self, event_queue, watch, timeout=DEFAULT_EMITTER_TIMEOUT, suppress
self._lock = threading.RLock()

def on_thread_stop(self):
if self.watch:
_fsevents.remove_watch(self.watch)
_fsevents.stop(self)
with self._lock:
self._watch = None
_fsevents.remove_watch(self.watch)
_fsevents.stop(self)

def queue_event(self, event):
# fsevents defaults to be recursive, so if the watch was meant to be non-recursive then we need to drop
Expand Down
11 changes: 7 additions & 4 deletions src/watchdog_fsevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,17 +784,20 @@ static PyObject *
watchdog_remove_watch(PyObject *self, PyObject *watch)
{
UNUSED(self);
PyObject *value = PyDict_GetItem(watch_to_stream, watch);
PyObject *streamref_capsule = PyDict_GetItem(watch_to_stream, watch);
if (!streamref_capsule) {
// A watch might have been removed explicitly before, in which case we can simply early out.
Py_RETURN_NONE;
}
PyDict_DelItem(watch_to_stream, watch);

FSEventStreamRef stream_ref = PyCapsule_GetPointer(value, NULL);
FSEventStreamRef stream_ref = PyCapsule_GetPointer(streamref_capsule, NULL);

FSEventStreamStop(stream_ref);
FSEventStreamInvalidate(stream_ref);
FSEventStreamRelease(stream_ref);

Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}

PyDoc_STRVAR(watchdog_stop__doc__,
Expand Down
4 changes: 1 addition & 3 deletions tests/test_fsevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ def on_thread_stop(self):
w = observer.schedule(FileSystemEventHandler(), a, recursive=False)
rmdir(a)
time.sleep(0.1)
with pytest.raises(KeyError):
# watch no longer exists!
observer.unschedule(w)
observer.unschedule(w)


def test_converting_cfstring_to_pyunicode():
Expand Down

0 comments on commit 8c4629c

Please sign in to comment.