Skip to content

Commit

Permalink
pybricks.tools: Don't block on task cancellation during shutdown.
Browse files Browse the repository at this point in the history
If a noncancellable task gets stuck, we still want to be able to shut down.

pybricks/support#1585
  • Loading branch information
laurensvalk committed Apr 5, 2024
1 parent a289bb1 commit 13dd65d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pybricks/tools/pb_module_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <pbio/task.h>
#include <pbsys/light.h>
#include <pbsys/program_stop.h>
#include <pbsys/status.h>

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

while (task->status == PBIO_ERROR_AGAIN) {
MICROPY_VM_HOOK_LOOP

// Stop waiting (and potentially blocking) in case of forced shutdown.
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)) {
break;
}
}

nlr_jump(nlr.ret_val);
Expand Down

0 comments on commit 13dd65d

Please sign in to comment.