Skip to content

Instantly share code, notes, and snippets.

@1fabunicorn
Created December 14, 2016 17:57
Show Gist options
  • Save 1fabunicorn/d05802ef15d95fe0295371d7d8047976 to your computer and use it in GitHub Desktop.
Save 1fabunicorn/d05802ef15d95fe0295371d7d8047976 to your computer and use it in GitHub Desktop.
Quick playing around with threading on python 2
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