Commit c57d32e 1 parent f72595e commit c57d32e Copy full SHA for c57d32e
File tree 1 file changed +10
-6
lines changed
1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change 6
6
from pathlib import Path
7
7
from typing import Callable
8
8
9
+ _INOTIFY_EXCEPTION : Exception | None = None
10
+ try :
11
+ from asyncinotify import Inotify , Mask
12
+ except Exception as ex :
13
+ _INOTIFY_EXCEPTION = ex
14
+ Mask = Inotify = None
15
+
16
+
9
17
_PATH = "/dev/bus/usb"
10
18
11
19
_LOGGER = logging .getLogger (__name__ )
@@ -38,12 +46,10 @@ def async_start(self) -> Callable[[], None]:
38
46
"""Start the watcher."""
39
47
if self ._task is not None :
40
48
raise RuntimeError ("Watcher already started" )
41
- try :
42
- from asyncinotify import Inotify # noqa
43
- except Exception as ex :
49
+ if _INOTIFY_EXCEPTION is not None :
44
50
raise InotifyNotAvailableError (
45
51
"Inotify not available on this platform"
46
- ) from ex
52
+ ) from _INOTIFY_EXCEPTION
47
53
self ._task = self ._loop .create_task (self ._watcher ())
48
54
return self ._async_stop
49
55
@@ -61,8 +67,6 @@ def _async_stop(self) -> None:
61
67
self ._task = None
62
68
63
69
async def _watcher (self ) -> None :
64
- from asyncinotify import Inotify , Mask
65
-
66
70
mask = (
67
71
Mask .CREATE
68
72
| Mask .MOVED_FROM
You can’t perform that action at this time.
0 commit comments