Skip to content

Commit 232980a

Browse files
committed
Change child services to a WeakSet
1 parent e3af5de commit 232980a

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

p2p/service.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
Callable,
99
List,
1010
Optional,
11-
Set,
1211
cast,
1312
)
1413
from weakref import WeakSet
@@ -35,8 +34,8 @@ def __init__(self) -> None:
3534

3635
class BaseService(ABC, CancellableMixin):
3736
logger: TraceLogger = None
38-
_child_services: Set['BaseService']
3937
# Use a WeakSet so that we don't have to bother updating it when tasks finish.
38+
_child_services: 'WeakSet[BaseService]'
4039
_tasks: 'WeakSet[asyncio.Future[Any]]'
4140
_finished_callbacks: List[Callable[['BaseService'], None]]
4241
# Number of seconds cancel() will wait for run() to finish.
@@ -52,7 +51,7 @@ def __init__(self,
5251
loop: asyncio.AbstractEventLoop = None) -> None:
5352
self.events = ServiceEvents()
5453
self._run_lock = asyncio.Lock()
55-
self._child_services = set()
54+
self._child_services = WeakSet()
5655
self._tasks = WeakSet()
5756
self._finished_callbacks = []
5857

@@ -167,14 +166,13 @@ def run_daemon(self, service: 'BaseService') -> None:
167166
"""
168167
if service.is_running:
169168
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"
171170
)
172171
elif service.is_cancelled:
173172
raise ValidationError(
174173
f"Can't restart daemon {service!r}, child of {self!r}: it's already completed"
175174
)
176175

177-
178176
self._child_services.add(service)
179177

180178
async def _run_daemon_wrapper() -> None:

0 commit comments

Comments
 (0)