Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class workingThread(Thread):
- def __init__(self, gui, testCase):
- Thread.__init__(self)
- self.myName = Thread.getName(self)
- self.start() # start the thread
- def core(self,arg,f) : # Where I check the flag and run the actual code
- # STOP
- if (self.StopFlag == True):
- if self.isAlive():
- self.doHouseCleaning()
- # none of following works all throw exceptions
- self.exit()
- self.join()
- self._Thread__stop()
- self._Thread_delete()
- self.quit()
- # Check if it's terminated or not
- if not(self.isAlive()):
- print self.myName + " terminated "
- # PAUSE
- elif (self.StopFlag == False) and not(self.isSet()):
- print self.myName + " paused"
- while not(self.isSet()):
- pass
- # RUN
- elif (self.StopFlag == False) and self.isSet():
- r = f(arg)
- import threading
- import time
- class MyThread(threading.Thread):
- def __init__(self):
- super(MyThread,self).__init__()
- self.count = 5
- def run(self):
- while self.count:
- print("I'm running for %i more seconds" % self.count)
- time.sleep(1)
- self.count -= 1
- t = MyThread()
- print("Starting %s" % t)
- t.start()
- # do whatever you need to do while the other thread is running
- t.join()
- print("%s finished" % t)
- Starting <MyThread(Thread-1, initial)>
- I'm running for 5 more seconds
- I'm running for 4 more seconds
- I'm running for 3 more seconds
- I'm running for 2 more seconds
- I'm running for 1 more seconds
- <MyThread(Thread-1, stopped 6712)> finished
- import urllib2
- urllib2.urlopen(url[, data][, timeout])
- import socket
- socket.setdefaulttimeout(timeout)
Add Comment
Please, Sign In to add comment