Skip to content

Instantly share code, notes, and snippets.

@gibizer
Created October 21, 2024 15:58
Show Gist options
  • Save gibizer/a3d03884db3ca32cbb16e55988b2f820 to your computer and use it in GitHub Desktop.
Save gibizer/a3d03884db3ca32cbb16e55988b2f820 to your computer and use it in GitHub Desktop.
import threading
import time
def some_work():
time.sleep(1)
print("a bit of work done")
def task(timeout: threading.Event):
while not timeout.is_set():
some_work()
print("timeout received")
def timeout_handler(timeout: threading.Event):
print("timeout")
timeout.set()
def main():
timeout = threading.Event()
threading.Timer(3.0, timeout_handler, args=(timeout,)).start()
task(timeout)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment