Skip to content

Commit 11dc2c4

Browse files
remote/coordinator: drop returns from finally clauses
Exceptions in finally clauses containing return statements are swallowed [1]. That means any exception raised in the try block and a subsequent KeyError in the finally block leads to the original exception being swallowed. Since Python 3.14 "the compiler emits a SyntaxWarning when a return, break or continue appears in a finally block (see PEP 765)." [2]. Fix this by moving the code relying on the session into the try clause making the return in the except clause obsolete. [1] https://peps.python.org/pep-0765/#motivation [2] https://docs.python.org/3.14/reference/compound_stmts.html#finally-clause Signed-off-by: Bastian Krause <bst@pengutronix.de>
1 parent ae2f2a5 commit 11dc2c4

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

labgrid/remote/coordinator.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,11 @@ async def request_task():
355355
finally:
356356
try:
357357
session = self.clients.pop(peer)
358+
running_request_task.cancel()
359+
await running_request_task
360+
logging.debug("client aborted %s, cancelled: %s", session, context.cancelled())
358361
except KeyError:
359362
logging.info("Never received startup from peer %s that disconnected", peer)
360-
return
361-
362-
running_request_task.cancel()
363-
await running_request_task
364-
logging.debug("client aborted %s, cancelled: %s", session, context.cancelled())
365363

366364
def _add_default_place(self, name):
367365
if name in self.places:
@@ -462,15 +460,13 @@ async def request_task():
462460

463461
try:
464462
session = self.exporters.pop(peer)
463+
for groupname, group in session.groups.items():
464+
for resourcename in group.copy():
465+
session.set_resource(groupname, resourcename, None)
466+
467+
logging.debug("exporter aborted %s, cancelled: %s", context.peer(), context.cancelled())
465468
except KeyError:
466469
logging.info("Never received startup from peer %s that disconnected", peer)
467-
return
468-
469-
for groupname, group in session.groups.items():
470-
for resourcename in group.copy():
471-
session.set_resource(groupname, resourcename, None)
472-
473-
logging.debug("exporter aborted %s, cancelled: %s", context.peer(), context.cancelled())
474470

475471
@locked
476472
async def AddPlace(self, request, context):

0 commit comments

Comments
 (0)