You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a data logger design that uses the main thread to log data from sensors, with simple time.sleep() between consecutive data points.
I also have a thread that handles HTTP requests so the logger can respond to requests to change some settings etc.
I employ a lock from the _thread module so the shared data between the main thread that stores data and the HTTP thread that reads data don't access the data at the same time.
All works well except that I still occasionally get un-handled exceptions. I've done what I could to handle exceptions that I've seen and I'm sure there are still situations that I've not anticipated. So I've added a watchdog timer to the code. The main thread feeds the dog every iteration before reading and logging sensor data. This works fine for the main thread but the HTTP thread is left unprotected from exceptions that can cause the thread to quit and me to lose control of the logger via HTTP requests. I wish there is a way to monitor threads from the main thread so it can restart threads that have crashed, maybe up to a limited amount of restarts before rebooting. Unfortunately I couldn't find anything in the _thread library that lets the main thread check the status of a thread like checking task status in ESP-IDF. I think it's probably a higher level module on CPython that can do that but maybe isn't part of micropython. This means each thread has to do something when crashing. So I've considered the following two approaches.
Wrap the HTTP thread inside a try-except clause to catch any un-handled exception and issue machine.reboot() whenever a thread causes an un-handled exception. This is brute force. Other threads need to be informed of the pending reboot and exit gracefully.
Have some global variables for the threads to report that they are still running by setting the respective global variable to 1. Have the main thread set these values to 0. Main thread will reboot if it detects a thread is no longer running, reading a 0 on its corresponding global variable. Use a lock when accessing these global variables.
So I wonder if I can get some advice on this. I've done 2 within ESP-IDF using tasks, flags, and mutex. I wonder what's supported in micropython besides starting threads, making and securing locks.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have a data logger design that uses the main thread to log data from sensors, with simple time.sleep() between consecutive data points.
I also have a thread that handles HTTP requests so the logger can respond to requests to change some settings etc.
I employ a lock from the _thread module so the shared data between the main thread that stores data and the HTTP thread that reads data don't access the data at the same time.
All works well except that I still occasionally get un-handled exceptions. I've done what I could to handle exceptions that I've seen and I'm sure there are still situations that I've not anticipated. So I've added a watchdog timer to the code. The main thread feeds the dog every iteration before reading and logging sensor data. This works fine for the main thread but the HTTP thread is left unprotected from exceptions that can cause the thread to quit and me to lose control of the logger via HTTP requests. I wish there is a way to monitor threads from the main thread so it can restart threads that have crashed, maybe up to a limited amount of restarts before rebooting. Unfortunately I couldn't find anything in the _thread library that lets the main thread check the status of a thread like checking task status in ESP-IDF. I think it's probably a higher level module on CPython that can do that but maybe isn't part of micropython. This means each thread has to do something when crashing. So I've considered the following two approaches.
So I wonder if I can get some advice on this. I've done 2 within ESP-IDF using tasks, flags, and mutex. I wonder what's supported in micropython besides starting threads, making and securing locks.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions