Skip to content

Commit

Permalink
pybricks/util_pb/pb_task: Don't wait for cancel on shutdown.
Browse files Browse the repository at this point in the history
Fixes pybricks/support#814 so the user can at
least turn the hub off without removing the batteries.
  • Loading branch information
laurensvalk committed Dec 8, 2022
1 parent 6a67a6c commit 7d34df4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
- Reverted Pybricks Code stop button raises `SystemAbort` instead of
`SystemExit` ([support#834]).
- Improved stop message raised on `SystemExit` and `SystemAbort` ([support#836]).
- Fixed Technic Hub and City Hub sometimes not shutting down when a Bluetooth
operation is busy ([support#814]).

[support#777]: https://github.com/pybricks/support/issues/777
[support#805]: https://github.com/pybricks/support/issues/805
[support#834]: https://github.com/pybricks/support/issues/814
[support#826]: https://github.com/pybricks/support/issues/826
[support#834]: https://github.com/pybricks/support/issues/834
[support#834]: https://github.com/pybricks/support/issues/836
Expand Down
12 changes: 11 additions & 1 deletion pybricks/util_pb/pb_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <pbio/error.h>
#include <pbio/task.h>
#include <pbsys/status.h>

#include "py/mpconfig.h"
#include "py/mperrno.h"
Expand Down Expand Up @@ -41,7 +42,16 @@ void pb_wait_task(pbio_task_t *task, mp_int_t timeout) {
} else {
pbio_task_cancel(task);

while (task->status == PBIO_ERROR_AGAIN) {
while (task->status == PBIO_ERROR_AGAIN
#if !PYBRICKS_PY_COMMON_CHARGER
// HACK: This ensures we don't make the application program wait
// forever for a failed task cancellation when shutdown is
// requested. See https://github.com/pybricks/pybricks-micropython/pull/129
// We can remove this hack once we can ensure that task
// cancellation does not fail (for known cases).
&& !pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)
#endif
) {
MICROPY_VM_HOOK_LOOP
}

Expand Down

0 comments on commit 7d34df4

Please sign in to comment.