Skip to content

Commit 13dd65d

Browse files
committed
pybricks.tools: Don't block on task cancellation during shutdown.
If a noncancellable task gets stuck, we still want to be able to shut down. pybricks/support#1585
1 parent a289bb1 commit 13dd65d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pybricks/tools/pb_module_tools.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <pbio/task.h>
1717
#include <pbsys/light.h>
1818
#include <pbsys/program_stop.h>
19+
#include <pbsys/status.h>
1920

2021
#include <pybricks/parameters.h>
2122
#include <pybricks/common.h>
@@ -115,6 +116,11 @@ void pb_module_tools_pbio_task_do_blocking(pbio_task_t *task, mp_int_t timeout)
115116

116117
while (task->status == PBIO_ERROR_AGAIN) {
117118
MICROPY_VM_HOOK_LOOP
119+
120+
// Stop waiting (and potentially blocking) in case of forced shutdown.
121+
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)) {
122+
break;
123+
}
118124
}
119125

120126
nlr_jump(nlr.ret_val);

0 commit comments

Comments
 (0)