Created
February 10, 2014 08:24
-
-
Save methane/8912245 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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