Skip to content

Commit

Permalink
catch asyncio/CancelledError instead of reading G_QUIT
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptosiek committed Oct 11, 2023
1 parent 49b1427 commit 85a3afd
Show file tree
Hide file tree
Showing 4 changed files with 503 additions and 486 deletions.
67 changes: 35 additions & 32 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,38 +850,41 @@ async def delay_init(self):
await self.logger.resume_start_stop()

async def keyboard_check(self):
while not self.G_QUIT:
app_logger.info(
"s:start/stop, l: lap, r:reset, p: previous screen, n: next screen, q: quit"
)
key = await self.loop.run_in_executor(None, input, "> ")

if key == "s":
self.logger.start_and_stop_manual()
elif key == "l":
self.logger.count_laps()
elif key == "r":
self.logger.reset_count()
elif key == "n" and self.gui:
self.gui.scroll_next()
elif key == "p" and self.gui:
self.gui.scroll_prev()
elif key == "q" and self.gui:
await self.quit()
##### temporary #####
# test hardware key signals
elif key == "m" and self.gui:
self.gui.enter_menu()
elif key == "v" and self.gui:
self.gui.press_space()
elif key == "," and self.gui:
self.gui.press_tab()
elif key == "." and self.gui:
self.gui.press_shift_tab()
elif key == "b" and self.gui:
self.gui.back_menu()
elif key == "c" and self.gui:
self.gui.get_screenshot()
try:
while True:
app_logger.info(
"s:start/stop, l: lap, r:reset, p: previous screen, n: next screen, q: quit"
)
key = await self.loop.run_in_executor(None, input, "> ")

if key == "s":
self.logger.start_and_stop_manual()
elif key == "l":
self.logger.count_laps()
elif key == "r":
self.logger.reset_count()
elif key == "n" and self.gui:
self.gui.scroll_next()
elif key == "p" and self.gui:
self.gui.scroll_prev()
elif key == "q" and self.gui:
await self.quit()
##### temporary #####
# test hardware key signals
elif key == "m" and self.gui:
self.gui.enter_menu()
elif key == "v" and self.gui:
self.gui.press_space()
elif key == "," and self.gui:
self.gui.press_tab()
elif key == "." and self.gui:
self.gui.press_shift_tab()
elif key == "b" and self.gui:
self.gui.back_menu()
elif key == "c" and self.gui:
self.gui.get_screenshot()
except asyncio.CancelledError:
pass

def set_logger(self, logger):
self.logger = logger
Expand Down
10 changes: 4 additions & 6 deletions modules/pyqt/menu/pyqt_course_menu_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,8 @@ async def update_display(self):

# sequentially draw with download
# 1st download check
if (
self.privacy_code is None
and self.config.api.check_ridewithgps_files(self.list_id, "1st")
if self.privacy_code is None and self.config.api.check_ridewithgps_files(
self.list_id, "1st"
):
self.draw_images(draw_map_image=True, draw_profile_image=False)
self.privacy_code = self.config.logger.course.get_ridewithgps_privacycode(
Expand All @@ -409,9 +408,8 @@ async def update_display(self):
self.list_id, self.privacy_code
)
# 2nd download with privacy_code check
elif (
self.privacy_code is not None
and self.config.api.check_ridewithgps_files(self.list_id, "2nd")
elif self.privacy_code is not None and self.config.api.check_ridewithgps_files(
self.list_id, "2nd"
):
self.draw_images(draw_map_image=False, draw_profile_image=True)
self.enable_next_button()
Expand Down
11 changes: 7 additions & 4 deletions modules/sensor/sensor_i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,13 @@ def start_coroutine(self):
asyncio.create_task(self.start())

async def start(self):
while not self.config.G_QUIT:
await self.sleep()
await self.update()
self.get_sleep_time(self.config.G_I2C_INTERVAL)
try:
while True:
await self.sleep()
await self.update()
self.get_sleep_time(self.config.G_I2C_INTERVAL)
except asyncio.CancelledError:
pass

async def update(self):
# timestamp
Expand Down
Loading

0 comments on commit 85a3afd

Please sign in to comment.