Skip to content

Instantly share code, notes, and snippets.

@mariocesar
Created September 30, 2020 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariocesar/de47664bbdfb1c2c8cf2e42321241cd1 to your computer and use it in GitHub Desktop.
Save mariocesar/de47664bbdfb1c2c8cf2e42321241cd1 to your computer and use it in GitHub Desktop.
from multiprocessing import Queue, Process
def do_something_really_slow(url):
...
result = Queue()
proc = Process(target=do_something_really_slow, args=(url,))
proc.start()
proc.join(timeout=5) # Wait 5 seconds, then timeout
if proc.exitcode != 0:
proc.kill() # Just in case
raise SystemError("We were unable to fetch the URL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment