Pi Pico: Thonny/CTRL-C with two threads #9617
-
I have searched for an answer to this but could not find other reference... I am using a Pico W. It has code to do stuff in two threads. It works fine - I can see the output of print statements from both cores. When I click CTRL-C, the first thread obviously stops. But the second one keeps going and no amount of CTRL-C clicking can stop it! Any ideas? Just to say, if I disconnect the board and CTRL-C quickly enough (before the second thread is launched) then there is no probem...) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You could use a shared global variable, say STOP = False
try:
run_my_application()
except: # ctrl-c or program error
STOP = True |
Beta Was this translation helpful? Give feedback.
You could use a shared global variable, say
STOP = False
. In the main thread, trapKeyboardInterrupt
and setSTOP = True
. On the second core, periodically check the variable. In fact it might be worth trapping any exception and settingSTOP = True
: