Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made modifications to main.py in the adafruithat and planktoscopehat #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions control/adafruithat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,24 @@ def handler_stop_signals(signum, _):
logger.success("Looks like the controller is set up and running, have fun!")
planktoscope.light.ready()

# With the creation of this dictionary to keep track of running threads, we can easily
# update the code if we decide to add another process, such as for the pump.
running_threads = {
"stepper": stepper_thread,
"imager": imager_thread
}

while run:
# TODO look into ways of restarting the dead threads
logger.trace("Running around in circles while waiting for someone to die!")
if not stepper_thread.is_alive():
logger.error("The stepper process died unexpectedly! Oh no!")
break
if not imager_thread or not imager_thread.is_alive():
logger.error("The imager process died unexpectedly! Oh no!")
# Check if any threads have terminated unexpectedly and log the error without exiting
for thread_name, thread in running_threads.items():
if not thread or not thread.is_alive():
logger.error(f"The {thread_name} process terminated unexpectedly!")
del running_threads[thread_name] # Remove the dead thread from the dictionary
# Check if all threads have terminated so we can exit the program
if not running_threads: #checks if there is no running thread left
logger.error("All processes terminated unexpectedly! Exiting...")
break
time.sleep(1)

Expand Down
21 changes: 16 additions & 5 deletions control/planktoscopehat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,25 @@ def handler_stop_signals(signum, frame):

logger.success("Looks like everything is set up and running, have fun!")


# With the creation of this dictionary to keep track of running threads, we can easily
# update the code if we decide to add another process, such as for the pump.
running_threads = {
"stepper": stepper_thread,
"imager": imager_thread
}

while run:
# TODO look into ways of restarting the dead threads
logger.trace("Running around in circles while waiting for someone to die!")
if not stepper_thread.is_alive():
logger.error("The stepper process died unexpectedly! Oh no!")
break
if not imager_thread or not imager_thread.is_alive():
logger.error("The imager process died unexpectedly! Oh no!")
# Check if any threads have terminated unexpectedly and log the error without exiting
for thread_name, thread in running_threads.items():
if not thread or not thread.is_alive():
logger.error(f"The {thread_name} process terminated unexpectedly!")
del running_threads[thread_name] # Remove the dead thread from the dictionary
# Check if all threads have terminated so we can exit the program
if not running_threads: #checks if there is no running thread left
logger.error("All processes terminated unexpectedly! Exiting...")
break
time.sleep(1)

Expand Down