Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python Threading Sample
placeholder docstring
import threading
import time
import random
def waitsome(n):
""" wait some time
seconds = random.randint(0,n*1000)/1000
print "waited: {} ms on {}.".format(1000*seconds,threading.currentThread().name)
if __name__ == "__main__":
# when we have made no threads, this returns 1.
# print threading.activeCount()
# this gives the main thread if no new threads have
# yet been initiated
# print threading.enumerate()
threadname = "randomthread"
mylist = []
for i in range(50):
mylist.append(threading.Thread(None, waitsome, threadname+str(i), [5]))
for thread in mylist:
print "Final (running) ActiveCount", threading.activeCount()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment