forked from gorakhargosh/watchdog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly clean up threads when stopping Inotify. Improve Eventle…
…t tests. (gorakhargosh#1070) * Improve cleaning up Inotify threads and add eventlet test cases. * Align SkipRepeatsQueue with Eventlet's Queue implementation. * Only run eventlet tests in Linux.
- Loading branch information
1 parent
4e9a86d
commit 29393f4
Showing
9 changed files
with
168 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
if __name__ == '__main__': | ||
import eventlet | ||
|
||
eventlet.monkey_patch() | ||
|
||
import signal | ||
import sys | ||
import tempfile | ||
|
||
from watchdog.observers import Observer | ||
from watchdog.events import LoggingEventHandler | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
def run_observer(): | ||
event_handler = LoggingEventHandler() | ||
observer = Observer() | ||
observer.schedule(event_handler, temp_dir) | ||
observer.start() | ||
eventlet.sleep(1) | ||
observer.stop() | ||
|
||
def on_alarm(signum, frame): | ||
print("Observer.stop() never finished!", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
signal.signal(signal.SIGALRM, on_alarm) | ||
signal.alarm(4) | ||
|
||
thread = eventlet.spawn(run_observer) | ||
thread.wait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
if __name__ == '__main__': | ||
import eventlet | ||
|
||
eventlet.monkey_patch() | ||
|
||
from watchdog.utils.bricks import SkipRepeatsQueue | ||
|
||
q = SkipRepeatsQueue(10) | ||
q.put('A') | ||
q.put('A') | ||
q.put('A') | ||
q.put('A') | ||
q.put('B') | ||
q.put('A') | ||
|
||
value = q.get() | ||
assert value == 'A' | ||
q.task_done() | ||
|
||
assert q.unfinished_tasks == 2 | ||
|
||
value = q.get() | ||
assert value == 'B' | ||
q.task_done() | ||
|
||
assert q.unfinished_tasks == 1 | ||
|
||
value = q.get() | ||
assert value == 'A' | ||
q.task_done() | ||
|
||
assert q.empty() | ||
assert q.unfinished_tasks == 0 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pytest | ||
import importlib | ||
|
||
from watchdog.utils import platform | ||
|
||
from .utils import run_isolated_test | ||
|
||
|
||
# Kqueue isn't supported by Eventlet, so BSD is out | ||
# Current usage ReadDirectoryChangesW on Windows is blocking, though async may be possible | ||
@pytest.mark.skipif(not platform.is_linux(), reason="Eventlet only supported in Linux") | ||
def test_observer_stops_in_eventlet(): | ||
if not importlib.util.find_spec('eventlet'): | ||
pytest.skip("eventlet not installed") | ||
|
||
run_isolated_test('eventlet_observer_stops.py') | ||
|
||
|
||
@pytest.mark.skipif(not platform.is_linux(), reason="Eventlet only supported in Linux") | ||
def test_eventlet_skip_repeat_queue(): | ||
if not importlib.util.find_spec('eventlet'): | ||
pytest.skip("eventlet not installed") | ||
|
||
run_isolated_test('eventlet_skip_repeat_queue.py') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters