Created
August 24, 2018 11:15
-
-
Save scriptpapi/ff75da1a3f9ccb28033a55752a8afebd to your computer and use it in GitHub Desktop.
python timer alarm script using multiprocessing
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
| from multiprocessing import Process | |
| import time | |
| class TimeoutException(Exception): | |
| pass | |
| timer = 5 | |
| def start_timer(): | |
| time.sleep(timer) | |
| raise TimeoutException | |
| def lazy_func(): | |
| time.sleep(10) | |
| def scrolldown(): | |
| try: | |
| lazy_func() | |
| except TimeoutException: | |
| print("timeout") | |
| i += 1 | |
| p1 = Process(target=start_timer) | |
| p2 = Process(target=scrolldown) | |
| i = 0 | |
| while True: | |
| p1.start() | |
| p2.start() | |
| p1.join() | |
| p2.join() | |
| if i == 2: | |
| break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment