Breaking News
Loading...
July 27, 2015

Python threading from a class

10:11 AM
Here is threading from a class written for Python v2.6
#!/usr/bin/python
import threading 
import time 

class Client(object):
 def test_thread(self):
  print "starting thread"
  self.thread = threading.Thread(target=self.run)
  self.thread.start()
  print "sleeping for 6 seconds"
  time.sleep(6)
  print "woken up"
  self.thread.join() 
 
 def run(self): 
  for i in range(5):
  print i
  time.sleep(1) 

c = Client() 
c.test_thread()
Source URL:http://www.gossamer-threads.com/lists/python/python/781285

0 comments:

Post a Comment

 
Toggle Footer