From 3b496bae8643564d85e6558b474e7499770c081b Mon Sep 17 00:00:00 2001 From: kuzh Date: Sun, 25 Feb 2024 23:40:49 +0100 Subject: [PATCH] Added main process to avoid error in the sub process. --- runtest.py | 19 +++++++++++++++++++ speedtest.py | 44 ++++++++++++++++---------------------------- 2 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 runtest.py diff --git a/runtest.py b/runtest.py new file mode 100644 index 0000000..14837d2 --- /dev/null +++ b/runtest.py @@ -0,0 +1,19 @@ + +import subprocess +import time +import datetime + + +if __name__ == "__main__": + # Replace 'script.py' with the name of the Python script you want to run + script_path = "speedtest.py" + schedule_time = "23:38" + repeat_count = 2 + while True: + current_time = datetime.datetime.now().strftime("%H:%M") + if current_time == schedule_time: + for i in range(repeat_count): + subprocess.run(["python", script_path]) + break + else: + time.sleep(1) diff --git a/speedtest.py b/speedtest.py index ff7bb0e..171d23b 100755 --- a/speedtest.py +++ b/speedtest.py @@ -1997,36 +1997,24 @@ def shell(): if args.share and not machine_format: printer('Share results: %s' % results.share()) - utilities.convert_and_save_to_xlsx(str(results), "tmp/f24-ch1.xlsx") + utilities.convert_and_save_to_xlsx(str(results), "tmp/dev-test.xlsx") -def main(iteration=1): - for i in range(iteration): - try: - shell() - except KeyboardInterrupt: - printer('\nCancelling...', error=True) - except (SpeedtestException, SystemExit): - e = get_exception() - # Ignore a successful exit, or argparse exit - if getattr(e, 'code', 1) not in (0, 2): - msg = '%s' % e - if not msg: - msg = '%r' % e - raise SystemExit('ERROR: %s' % msg) - i+=1 - if i == iteration: - break +def main(): + try: + shell() + except KeyboardInterrupt: + printer('\nCancelling...', error=True) + except (SpeedtestException, SystemExit): + e = get_exception() + # Ignore a successful exit, or argparse exit + if getattr(e, 'code', 1) not in (0, 2): + msg = '%s' % e + if not msg: + msg = '%r' % e + raise SystemExit('ERROR: %s' % msg) + if __name__ == '__main__': - schedule_time = "23:13" - repeat_count = 0 - while True: - current_time = datetime.datetime.now().strftime("%H:%M") - if current_time == schedule_time: - main(1) - break - else: - time.sleep(1) - # main(5) \ No newline at end of file + main() \ No newline at end of file