Skip to content

Instantly share code, notes, and snippets.

@scriptpapi
Created August 24, 2018 11:15
Show Gist options
  • Select an option

  • Save scriptpapi/ff75da1a3f9ccb28033a55752a8afebd to your computer and use it in GitHub Desktop.

Select an option

Save scriptpapi/ff75da1a3f9ccb28033a55752a8afebd to your computer and use it in GitHub Desktop.
python timer alarm script using multiprocessing
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