Skip to content

Commit b6f700d

Browse files
fmoessbauerjan-kiszka
authored andcommitted
fix: cancel pending tasks on exception
In case one task raises an exception that is not ignore-handled, we must cancel all other tasks as well. Otherwise it takes quite long until the overall execution finishes. Fixes: f4beea3 ("graceful cancellation of external commands") Signed-off-by: Felix Moessbauer <[email protected]> Signed-off-by: Jan Kiszka <[email protected]>
1 parent 1c33810 commit b6f700d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

kas/libkas.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ async def run_cmd_async(cmd, cwd, env=None, fail=True, liveupdate=False,
178178
await asyncio.gather(*[asyncio.shield(t) for t in tasks])
179179
ret = await asyncio.shield(process.wait())
180180
except asyncio.CancelledError:
181-
process.terminate()
181+
try:
182+
process.terminate()
183+
except ProcessLookupError:
184+
# Process already exited between the cancel and us reaching here.
185+
pass
182186
logging.debug('Command "%s" cancelled', cmdstr)
183187
await process.wait()
184188
raise
@@ -244,7 +248,11 @@ def repos_fetch(repos):
244248
try:
245249
loop.run_until_complete(asyncio.gather(*tasks))
246250
except CommandExecError as e:
251+
[t.cancel() for t in tasks]
247252
raise TaskExecError('fetch repos', e.ret_code)
253+
except KasUserError:
254+
[t.cancel() for t in tasks]
255+
raise
248256

249257

250258
def repos_apply_patches(repos):
@@ -264,7 +272,11 @@ def repos_apply_patches(repos):
264272
try:
265273
loop.run_until_complete(asyncio.gather(*tasks))
266274
except CommandExecError as e:
275+
[t.cancel() for t in tasks]
267276
raise TaskExecError('apply patches', e.ret_code)
277+
except KasUserError:
278+
[t.cancel() for t in tasks]
279+
raise
268280

269281

270282
def get_buildtools_dir():

0 commit comments

Comments
 (0)