Quantcast
Viewing all articles
Browse latest Browse all 4854

MicroPython • Re: How to exit gracefully from the second Pico thread ?

I do like this and it works ! Image may be NSFW.
Clik here to view.
:)
It seems that in the first example the EndFlag was passed by value, not by reference...
By the way, is there a method to know when a thread is terminated ? Or wait for it to finish ? In the Pico/MicroPython context...

Code:

import _threadimport timeterminate = Falsedef my_thread():  global terminate  print("New thread is running...")  while not terminate:    time.sleep(0.2)   print("New thread is terminating gracefully.")    _thread.start_new_thread(my_thread, ())try:  while True:    time.sleep(2) except KeyboardInterrupt:  terminate = True  time.sleep(0.3)  print("Main thread terminated gracefully.")

Statistics: Posted by Marus780 — Fri Mar 01, 2024 1:33 pm



Viewing all articles
Browse latest Browse all 4854

Trending Articles