Skip to content

Commit e205203

Browse files
authored
Properly handle multiple shutdown requests (#49)
1 parent 49acedd commit e205203

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

python/golem_task_api/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,13 @@ class AppClient(abc.ABC):
124124
def __init__(self, service: TaskApiService) -> None:
125125
self._service = service
126126
self._kill_switch = Wrapper()
127+
self._shutdown_future = asyncio.get_event_loop().create_future()
127128

128129
async def shutdown(self, timeout: float = SOFT_SHUTDOWN_TIMEOUT) -> None:
129-
if not self._kill_switch.cancelled:
130-
self._kill_switch.cancel(ShutdownException("Shutdown requested"))
130+
if self._kill_switch.cancelled:
131+
await self._shutdown_future
132+
return
133+
self._kill_switch.cancel(ShutdownException("Shutdown requested"))
131134
if not self._service.running():
132135
return
133136
try:
@@ -143,6 +146,8 @@ async def shutdown(self, timeout: float = SOFT_SHUTDOWN_TIMEOUT) -> None:
143146
if self._service.running():
144147
await self._service.stop()
145148
await self._service.wait_until_shutdown_complete()
149+
finally:
150+
self._shutdown_future.set_result(None)
146151

147152
@abc.abstractmethod
148153
async def _soft_shutdown(self) -> None:

python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='Golem-Task-Api',
5-
version='0.19.0',
5+
version='0.19.1',
66
url='https://github.com/golemfactory/golem/task-api/python',
77
maintainer='The Golem team',
88
maintainer_email='tech@golem.network',

0 commit comments

Comments
 (0)