Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 940deeb

Browse files
committed
Unlock the GIL while accessing queues
Keeping the GIL locked while sending to full queues or receiving from empty queues results in a deadlock, because no other Python code can execute to put() or get() from the queue.
1 parent 055728a commit 940deeb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

esp32/mods/moduqueue.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,13 @@ STATIC mp_obj_t mp_queue_put(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
9191
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
9292
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), allowed_args, args);
9393

94+
MP_THREAD_GIL_EXIT();
9495
uint32_t timeout_ms = (args[2].u_obj == mp_const_none) ? portMAX_DELAY : mp_obj_get_int_truncated(args[2].u_obj);
9596
if (!xQueueSend(self->handle, (void *)&args[0].u_obj, args[1].u_bool ? (TickType_t)(timeout_ms / portTICK_PERIOD_MS) : 0)) {
97+
MP_THREAD_GIL_ENTER();
9698
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Full"));
9799
}
100+
MP_THREAD_GIL_ENTER();
98101

99102
return mp_const_none;
100103
}
@@ -113,9 +116,12 @@ STATIC mp_obj_t mp_queue_get(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
113116

114117
uint32_t timeout_ms = (args[1].u_obj == mp_const_none) ? portMAX_DELAY : mp_obj_get_int_truncated(args[1].u_obj);
115118
mp_obj_t item;
119+
MP_THREAD_GIL_EXIT();
116120
if (!xQueueReceive(self->handle, (void *)&item, args[0].u_bool ? (TickType_t)(timeout_ms / portTICK_PERIOD_MS) : 0)) {
121+
MP_THREAD_GIL_ENTER();
117122
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Empty"));
118123
}
124+
MP_THREAD_GIL_ENTER();
119125

120126
return item;
121127
}

0 commit comments

Comments
 (0)