Skip to content

Commit

Permalink
Improved thread safety when killing the app
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineRichard committed Sep 25, 2024
1 parent 73ff931 commit 2f93332
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import logging
import time
import copy
import sys

from src.terrain_management.large_scale_terrain.utils import ScopedTimer, BoundingBox, CraterMetadata
from src.terrain_management.large_scale_terrain.crater_generation import (
Expand Down Expand Up @@ -593,8 +594,13 @@ def update_high_res_dem(self, coords: Tuple[float, float]) -> bool:
# Threaded update, the function will return before the update is done
thread = threading.Thread(target=self.threaded_high_res_dem_update)
thread.start()
thread.join()
self.sim_is_warm = True
updated = True
if not self.monitor_thread.thread.is_alive():
logger.warn("Simulation exited before being fully initialized. Trying to exit.")
logger.warn("You may need to kill the process manually. Or use Ctrl + \ to exit.")
sys.exit(0)

# Map update if the block has changed
if self.current_block_coord != block_coordinates:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ def shutdown(self) -> None:
while not self.input_queue.empty():
self.input_queue.get()
logger.debug("Worker input queue emptied.")
try:
while True:
self.input_queue.task_done()
except:
pass
self.input_queue.join()
logger.debug("Worker input queue joined.")

Expand Down Expand Up @@ -522,6 +527,11 @@ def shutdown(self) -> None:
while not self.input_queue.empty():
self.input_queue.get()
self.input_queue.task_done()
try:
while True:
self.input_queue.task_done()
except:
pass
logger.debug("Emptied input queue.")
self.input_queue.join()
logger.debug("Joined input queue.")
Expand Down

0 comments on commit 2f93332

Please sign in to comment.