Skip to content

Instantly share code, notes, and snippets.

@wfng92
Last active April 10, 2020 07:12
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 wfng92/f8a677d74fce8bb752290de4f64f966d to your computer and use it in GitHub Desktop.
Save wfng92/f8a677d74fce8bb752290de4f64f966d to your computer and use it in GitHub Desktop.
from concurrent.futures import ThreadPoolExecutor
import time
def wait_function(x, y):
print('Task(', x,'multiply', y, ') started')
time.sleep(2)
print('Task(', x,'multiply', y, ') completed')
return x * y
with ThreadPoolExecutor(max_workers=1) as executor:
future = executor.submit(wait_function, 3, 4)
while True:
if(future.running()):
print("Task 1 running")
elif(future.done()):
print(future.result())
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment