Skip to content

Commit 27a9a14

Browse files
authored
feat: improve example to show how to stop the watcher (#6)
1 parent 7e7d2ed commit 27a9a14

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

examples/usb_device_added_or_removed.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ async def main() -> None:
77
"""Main entry point of the program."""
88
try:
99
watcher = AIOUSBWatcher()
10-
watcher.async_start()
10+
cancel = watcher.async_start()
1111
except InotifyNotAvailableError as ex:
1212
print(ex)
1313
return
1414

1515
watcher.async_register_callback(lambda: print("USB device added/removed"))
1616
event = asyncio.Event()
17-
await event.wait()
17+
try:
18+
await event.wait()
19+
finally:
20+
cancel()
1821

1922

2023
if __name__ == "__main__":

0 commit comments

Comments
 (0)