Guest User

Untitled

a guest
Jan 18th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. class workingThread(Thread):
  2.  
  3. def __init__(self, gui, testCase):
  4. Thread.__init__(self)
  5. self.myName = Thread.getName(self)
  6. self.start() # start the thread
  7.  
  8. def core(self,arg,f) : # Where I check the flag and run the actual code
  9.  
  10. # STOP
  11. if (self.StopFlag == True):
  12. if self.isAlive():
  13.  
  14. self.doHouseCleaning()
  15. # none of following works all throw exceptions
  16. self.exit()
  17. self.join()
  18. self._Thread__stop()
  19. self._Thread_delete()
  20. self.quit()
  21.  
  22. # Check if it's terminated or not
  23. if not(self.isAlive()):
  24. print self.myName + " terminated "
  25.  
  26.  
  27.  
  28. # PAUSE
  29. elif (self.StopFlag == False) and not(self.isSet()):
  30.  
  31. print self.myName + " paused"
  32.  
  33. while not(self.isSet()):
  34. pass
  35.  
  36. # RUN
  37. elif (self.StopFlag == False) and self.isSet():
  38. r = f(arg)
  39.  
  40. import threading
  41. import time
  42.  
  43. class MyThread(threading.Thread):
  44.  
  45. def __init__(self):
  46. super(MyThread,self).__init__()
  47. self.count = 5
  48.  
  49. def run(self):
  50. while self.count:
  51. print("I'm running for %i more seconds" % self.count)
  52. time.sleep(1)
  53. self.count -= 1
  54.  
  55. t = MyThread()
  56. print("Starting %s" % t)
  57. t.start()
  58. # do whatever you need to do while the other thread is running
  59. t.join()
  60. print("%s finished" % t)
  61.  
  62. Starting <MyThread(Thread-1, initial)>
  63. I'm running for 5 more seconds
  64. I'm running for 4 more seconds
  65. I'm running for 3 more seconds
  66. I'm running for 2 more seconds
  67. I'm running for 1 more seconds
  68. <MyThread(Thread-1, stopped 6712)> finished
  69.  
  70. import urllib2
  71. urllib2.urlopen(url[, data][, timeout])
  72.  
  73. import socket
  74. socket.setdefaulttimeout(timeout)
Add Comment
Please, Sign In to add comment