Created
October 21, 2024 15:58
-
-
Save gibizer/a3d03884db3ca32cbb16e55988b2f820 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 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