Browse Source

Made time.sleep async friendly

atexit
Raphael Roberts 6 years ago
parent
commit
d1c8c0c73f
  1. 9
      ctabus/__init__.py

9
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

Loading…
Cancel
Save