From d1c8c0c73f5561d39c9018ec60363ff306fc06bd Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Sat, 12 Oct 2019 14:36:15 -0500 Subject: [PATCH] Made time.sleep async friendly --- ctabus/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ctabus/__init__.py b/ctabus/__init__.py index 7f605fc..795b6dd 100644 --- a/ctabus/__init__.py +++ b/ctabus/__init__.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 from dateutil import tz from dateutil.parser import parse as date_parse +from threading import Event import argparse import datetime @@ -22,6 +23,7 @@ from ctabus.internal.notification import NotificationManager, HAS_NOTIFICATION HAS_TOAST = shutil.which("termux-toast") is not None CHICAGO_TZ = tz.gettz("America/Chicago") DATETIME_FORMAT = "%A, %B %e, %Y %H:%M:%S" +EXIT = Event() # https://stackoverflow.com/a/5967539 parser = argparse.ArgumentParser(prog="ctabus") @@ -159,7 +161,8 @@ class Table: class CTABUSNotifictaionManager(NotificationManager): def on_done(self): - quit() + EXIT.set() + quit(0) def gen_list(objs, data, *displays, key=None, sort=0, num_pic=True): @@ -184,7 +187,7 @@ def gen_list(objs, data, *displays, key=None, sort=0, num_pic=True): which = display_table.get_name_interactive(data) return which except KeyboardInterrupt: - quit() + quit(0) config = """\ @@ -301,7 +304,7 @@ def _main_periodic(args, stop_id, init_data): e = time.perf_counter() - s print("Error fetching times") if e < args.periodic: - time.sleep(args.periodic - e) + EXIT.wait(args.periodic - e) except KeyboardInterrupt: _done = True