Created
December 14, 2016 17:57
-
-
Save 1fabunicorn/d05802ef15d95fe0295371d7d8047976 to your computer and use it in GitHub Desktop.
Quick playing around with threading on python 2
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
import threading | |
from time import sleep | |
import random | |
y = random.randint | |
z = sleep | |
class testA(threading.Thread): | |
def run(self): | |
randomNum = random.randint(0,5) | |
print "time that A will sleep is " + str(randomNum) + " second" | |
sleep(randomNum) | |
for x in range(3): | |
print 0, | |
print "Done with " + threading.currentThread().getName() | |
class testB(threading.Thread): | |
def run(self): | |
for x in range(5): | |
print 1, #comma for new line | |
print "Done with " + threading.currentThread().getName() | |
a = testA(name="a") | |
b = testB(name="b") | |
a.start() | |
b.start() | |
print "\n" | |
#print threading.enumerate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment