Yes, threading does all sorts of weird stuff -And this is the result of a Ctrl-C via 'minicom' rather than Thonny -And then it hung solid.
This worked for me ...
Code:
import timeimport _threaddef MyThread(): while True: print("Tick") time.sleep(1)_thread.start_new_thread(MyThread, ())while True: time.sleep(1)Code:
TickTickTraceback (most recent call last): File "<stdin>", line 12, in <module>KeyboardInterrupt:>MicroPython v1.23.0-preview.297.g35e8d184b.dirty on 2024-03-27; Raspberry Pi Pico with RP2040Type "help()" for more information.>>> TickFATAL: uncaught exception 20008040OSErrorThis worked for me ...
Code:
import timeimport _threadrunning = Truefinished = Falsedef MyThread(): global finished print("Thread is starting") while running: print("Tick") time.sleep(1) print("Thread is finishing") finished = True_thread.start_new_thread(MyThread, ())try: while True: time.sleep(1)except KeyboardInterrupt: print("Stopping thread") running = False while not finished: pass print("Thread reports finished")Statistics: Posted by hippy — Sun Apr 07, 2024 7:15 pm