Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import threading
  4. import time
  5.  
  6. exitFlag = 0
  7.  
  8. class myThread (threading.Thread):
  9. def __init__(self, threadID, name, counter):
  10. threading.Thread.__init__(self)
  11. self.threadID = threadID
  12. self.name = name
  13. self.counter = counter
  14. def run(self):
  15. print ("Starting " + self.name)
  16. print_time(self.name, self.counter, 5)
  17. print ("Exiting " + self.name)
  18.  
  19. def print_time(threadName, delay, counter):
  20. while counter:
  21. if exitFlag:
  22. threadName.exit()
  23. time.sleep(delay)
  24. print ("%s: %s" % (threadName, time.ctime(time.time())))
  25. counter -= 1
  26.  
  27. myList = ['string0', 'string1', 'string2']
  28.  
  29. def processFunc():
  30. count = 0
  31. for data in myList:
  32. count += 1
  33. mythread = myThread(count, "Thread-" + str(count), count)
  34. mythread.start()
  35. mythread.join()
  36.  
  37. processFunc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement