Skip to content

Commit

Permalink
refactor: exception handlings
Browse files Browse the repository at this point in the history
  • Loading branch information
castilloglenn committed Apr 14, 2024
1 parent 673f09a commit ccd208c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 2 additions & 0 deletions dataflow_animation/client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def setup(filepath):

renderer.init()
renderer.run()
except KeyboardInterrupt:
logging.info("Exiting...")
finally:
renderer.stop()
if watcher_thread.is_alive():
Expand Down
16 changes: 5 additions & 11 deletions dataflow_animation/core/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,17 @@ def init(self):
self.screen = pygame.display.set_mode((CONFIG.width, CONFIG.height))
self.clock = pygame.time.Clock()

try:
self.run()
finally:
pygame.quit()
logging.info("Pygame stopped.")
self.run()

def run(self):
try:
while self.running:
self.parse_events()
self.render()

except pygame.error as e:
logging.error("Pygame error: %s", e)

except KeyboardInterrupt:
logging.info("Pygame exiting...")
finally:
pygame.quit()
logging.info("Pygame stopped.")

def parse_events(self):
for event in pygame.event.get():
Expand All @@ -77,7 +71,7 @@ def build_animation_sequence(self):
# pylint: disable=W0718
except Exception as e:
logging.error(
"Error playing animation:\n%s: %s",
"Error building the animations:\n%s: %s",
type(e).__name__,
e,
)
Expand Down

0 comments on commit ccd208c

Please sign in to comment.