Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # threading_simple_parallel_without_join_demo1.py -- Note: the threads set for 15 seconds may appear in a random order
- # Not sure sure why there seems to be extra linefeeds
- from threading import Thread
- import time
- def worker(order,s):
- myList=[]
- for i in range(s+1): # do something
- myList.append(i)
- time.sleep(s)
- print '\n\n\nThread#%d Seconds: %d Current Time: %s \n\nWork: %s' % (order+1,s,time.strftime("%I:%M:%S"),myList)
- #
- work='15 15 15 15 15 10 15 20 15 5 15 15'.split() # one 5s : nine 10s : ten 10s : one 20s
- print "The last thread output (#8) should appear after 20 seconds"
- threads = []
- for i in range(len(work)):
- t = Thread(target=worker, args=(i, int(work[i])))
- t.start()
- threads.append(t)
- print "End Of Script Without Join!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement