8
8
Callable ,
9
9
List ,
10
10
Optional ,
11
- Set ,
12
11
cast ,
13
12
)
14
13
from weakref import WeakSet
@@ -35,8 +34,8 @@ def __init__(self) -> None:
35
34
36
35
class BaseService (ABC , CancellableMixin ):
37
36
logger : TraceLogger = None
38
- _child_services : Set ['BaseService' ]
39
37
# Use a WeakSet so that we don't have to bother updating it when tasks finish.
38
+ _child_services : 'WeakSet[BaseService]'
40
39
_tasks : 'WeakSet[asyncio.Future[Any]]'
41
40
_finished_callbacks : List [Callable [['BaseService' ], None ]]
42
41
# Number of seconds cancel() will wait for run() to finish.
@@ -52,7 +51,7 @@ def __init__(self,
52
51
loop : asyncio .AbstractEventLoop = None ) -> None :
53
52
self .events = ServiceEvents ()
54
53
self ._run_lock = asyncio .Lock ()
55
- self ._child_services = set ()
54
+ self ._child_services = WeakSet ()
56
55
self ._tasks = WeakSet ()
57
56
self ._finished_callbacks = []
58
57
@@ -167,14 +166,13 @@ def run_daemon(self, service: 'BaseService') -> None:
167
166
"""
168
167
if service .is_running :
169
168
raise ValidationError (
170
- f"Can't start daemon { child_service !r} , child of { self !r} : it's already running"
169
+ f"Can't start daemon { service !r} , child of { self !r} : it's already running"
171
170
)
172
171
elif service .is_cancelled :
173
172
raise ValidationError (
174
173
f"Can't restart daemon { service !r} , child of { self !r} : it's already completed"
175
174
)
176
175
177
-
178
176
self ._child_services .add (service )
179
177
180
178
async def _run_daemon_wrapper () -> None :
0 commit comments