Skip to content

Instantly share code, notes, and snippets.

@j-thepac
Created July 3, 2022 13:20
Show Gist options
  • Save j-thepac/f9e11eef7fe0e81995fa4b6484794d6e to your computer and use it in GitHub Desktop.
Save j-thepac/f9e11eef7fe0e81995fa4b6484794d6e to your computer and use it in GitHub Desktop.
multithread
import concurrent.futures
import time ,datetime
start = datetime.datetime.now()
def do_something(seconds):
print(f'Sleeping {seconds}')
time.sleep(seconds)
return f'Done Sleeping...{seconds}'
with concurrent.futures.ThreadPoolExecutor() as executor:
results = executor.map(do_something, [1,1])
for i in results:print(i)
print(datetime.datetime.now()-start) #01.003
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment