[python/helpers] Change interrupt check delay

Keyboard interruption used to be checked once every 20000 calls to
micropython_port_vm_hook_loop. However, if costly functions were
executed in between calls to this method, the delay for activating
interruptions would increase.
Now, keyboard interruption is checked after a fixed amount of time has
passed. This way, if the process waits a long time between two calls
to micropython_port_vm_hook_loop, it is still interrupted in a timely
manner.

Change-Id: I37ca3bd4a996fa086078f504340dd857526e356a
This commit is contained in:
Gabriel Ozouf
2020-08-12 11:08:54 +02:00
committed by LeaNumworks
parent 34ebf1e6e0
commit 7dcf1662b0

View File

@@ -12,12 +12,15 @@ bool micropython_port_vm_hook_loop() {
/* Doing too many things here slows down Python execution quite a lot. So we
* only do things once in a while and return as soon as possible otherwise. */
static int c = 0;
c = (c + 1) % 20000;
if (c != 0) {
static uint64_t t = Ion::Timing::millis();
static constexpr uint64_t delay = 100;
uint64_t t2 = Ion::Timing::millis();
if (t2 - t < delay) {
return false;
}
t = t2;
micropython_port_vm_hook_refresh_print();
// Check if the user asked for an interruption from the keyboard