Skip to content

Instantly share code, notes, and snippets.

@eriky
Created January 28, 2020 10:46
Show Gist options
  • Save eriky/a311abd2e1433dd7ff2cbe5ed5d95968 to your computer and use it in GitHub Desktop.
Save eriky/a311abd2e1433dd7ff2cbe5ed5d95968 to your computer and use it in GitHub Desktop.
from concurrent.futures import ThreadPoolExecutor
from time import sleep
def return_after_5_secs(message):
sleep(5)
return message
pool = ThreadPoolExecutor(3)
future = pool.submit(return_after_5_secs,
("Hello world"))
print(future.done())
# False
sleep(5)
print(future.done())
# True
print(future.result())
# Hello World
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment