Skip to content

Instantly share code, notes, and snippets.

@methane
Created February 10, 2014 08:24
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 methane/8912245 to your computer and use it in GitHub Desktop.
Save methane/8912245 to your computer and use it in GitHub Desktop.
$ python s.py
Falling asleep
Falling asleep
Falling asleep
Falling asleep
Falling asleep
Falling asleep
Falling asleepFalling asleep
Falling asleep
Falling asleep
Waked up
Waked up
Waked up
Waked up
Waked up
Waked up
Waked upWaked up
Waked up
Waked up
3.00400996208 secs
from __future__ import absolute_import, division, print_function, unicode_literals
import threading
import time
def thread():
print("Falling asleep")
time.sleep(3)
print("Waked up")
t1 = time.time()
threads = []
for i in range(10):
th = threading.Thread(target=thread)
th.start()
threads.append(th)
for th in threads:
th.join()
print(time.time()-t1, "secs")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment