Skip to content

Commit 996a075

Browse files
fix: handle QueueFull exception in file watch (#342)
Signed-off-by: Alex <[email protected]>
1 parent 586ea78 commit 996a075

File tree

1 file changed

+40
-32
lines changed

1 file changed

+40
-32
lines changed

extensions/eda/plugins/event_source/file_watch.py

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,47 +41,55 @@ def __init__(self: "Handler", **kwargs: Any) -> None:
4141
RegexMatchingEventHandler.__init__(self, **kwargs)
4242

4343
def on_created(self: "Handler", event: FileSystemEvent) -> None:
44-
loop.call_soon_threadsafe(
45-
queue.put_nowait,
46-
{
47-
"change": "created",
48-
"src_path": event.src_path,
49-
"type": event.__class__.__name__,
50-
"root_path": root_path,
51-
},
44+
asyncio.run_coroutine_threadsafe(
45+
queue.put(
46+
{
47+
"change": "created",
48+
"src_path": event.src_path,
49+
"type": event.__class__.__name__,
50+
"root_path": root_path,
51+
},
52+
),
53+
loop,
5254
)
5355

5456
def on_deleted(self: "Handler", event: FileSystemEvent) -> None:
55-
loop.call_soon_threadsafe(
56-
queue.put_nowait,
57-
{
58-
"change": "deleted",
59-
"src_path": event.src_path,
60-
"type": event.__class__.__name__,
61-
"root_path": root_path,
62-
},
57+
asyncio.run_coroutine_threadsafe(
58+
queue.put(
59+
{
60+
"change": "deleted",
61+
"src_path": event.src_path,
62+
"type": event.__class__.__name__,
63+
"root_path": root_path,
64+
},
65+
),
66+
loop,
6367
)
6468

6569
def on_modified(self: "Handler", event: FileSystemEvent) -> None:
66-
loop.call_soon_threadsafe(
67-
queue.put_nowait,
68-
{
69-
"change": "modified",
70-
"src_path": event.src_path,
71-
"type": event.__class__.__name__,
72-
"root_path": root_path,
73-
},
70+
asyncio.run_coroutine_threadsafe(
71+
queue.put(
72+
{
73+
"change": "modified",
74+
"src_path": event.src_path,
75+
"type": event.__class__.__name__,
76+
"root_path": root_path,
77+
},
78+
),
79+
loop,
7480
)
7581

7682
def on_moved(self: "Handler", event: FileSystemEvent) -> None:
77-
loop.call_soon_threadsafe(
78-
queue.put_nowait,
79-
{
80-
"change": "moved",
81-
"src_path": event.src_path,
82-
"type": event.__class__.__name__,
83-
"root_path": root_path,
84-
},
83+
asyncio.run_coroutine_threadsafe(
84+
queue.put(
85+
{
86+
"change": "moved",
87+
"src_path": event.src_path,
88+
"type": event.__class__.__name__,
89+
"root_path": root_path,
90+
},
91+
),
92+
loop,
8593
)
8694

8795
observer = Observer()

0 commit comments

Comments
 (0)