Created
August 30, 2023 23:13
-
-
Save ahmadpoorgholam/924c80f7d5af1b00764e1d01b1c4415f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from threading import Thread, Event | |
from time import sleep | |
import sys | |
done = Event() | |
def work(work_seconds=1): | |
sleep(1) | |
print("exit from timer thread") | |
sys.exit(0) | |
def longer_operation(): | |
print("longer main") | |
sleep(10) | |
def main(): | |
parser = argparse.ArgumentParser(prog="myprogram") | |
parser.add_argument("--timeout", help="time to wait before timeout", type=int) | |
parser.add_argument("--work", help="time to work", type=int) | |
args = parser.parse_args() | |
worker_thread = Thread(target=work, name="worker", args=(args.work,)) | |
worker_thread.start() | |
longer_operation() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment