Hello,
I cannot find a good answer for this online, so I'm hoping someone can help, or point me in the right direction.
I am using Micropython '_thread' to run an additional task - my Pico W is acting as a webserver, and on a separate thread is controlling some relays depending on info pulled from the website. It's all working, probably not fantastically implemented (I'm a novice!) but it works.
When the pico is plugged in to an external power souce, no issues whatsoever.
When i am modding the code in Thonny, and running from there (ie, running code on the Pico via Thonny) it seems to have issues when I ctrl-c to stop the program.
My belief is that 1 thread or the main program keeps running, and therefore the Pico still appears busy to Thonny. I have to force reset by unplugging and plugging back in. Annoying.
I assume I am doing something wrong with shutting down the thread (or main program) - my vague understanding from reading around is that potentially only the thread or the main program will receive the keyboard interrupt, and this can be unpredictable. Is this correct?
I have implemented in both thread and main, a try/except statement that should catch the keyboard interrupt and calls _thread.exit() and sys.exit(). However this doesn't seem to help. I have also seen the trick of using flags and a while True statement - but this will not work for me as my thread is sleeping quite a lot of the time and therefore doesn't see the flags immediately (can be up to ~12 hours delay).
Could anyone post some code where they have implemented threading with correct 'clean exit' strategy?
I am 100% sure this is a threading issue, as if i don't start the thread, all works normally.
Many thanks for any help!!
I cannot find a good answer for this online, so I'm hoping someone can help, or point me in the right direction.
I am using Micropython '_thread' to run an additional task - my Pico W is acting as a webserver, and on a separate thread is controlling some relays depending on info pulled from the website. It's all working, probably not fantastically implemented (I'm a novice!) but it works.
When the pico is plugged in to an external power souce, no issues whatsoever.
When i am modding the code in Thonny, and running from there (ie, running code on the Pico via Thonny) it seems to have issues when I ctrl-c to stop the program.
My belief is that 1 thread or the main program keeps running, and therefore the Pico still appears busy to Thonny. I have to force reset by unplugging and plugging back in. Annoying.
I assume I am doing something wrong with shutting down the thread (or main program) - my vague understanding from reading around is that potentially only the thread or the main program will receive the keyboard interrupt, and this can be unpredictable. Is this correct?
I have implemented in both thread and main, a try/except statement that should catch the keyboard interrupt and calls _thread.exit() and sys.exit(). However this doesn't seem to help. I have also seen the trick of using flags and a while True statement - but this will not work for me as my thread is sleeping quite a lot of the time and therefore doesn't see the flags immediately (can be up to ~12 hours delay).
Could anyone post some code where they have implemented threading with correct 'clean exit' strategy?
I am 100% sure this is a threading issue, as if i don't start the thread, all works normally.
Many thanks for any help!!
Statistics: Posted by czarop — Sun Apr 07, 2024 10:16 am