
下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
#!/usr/bin/env python"""testthread.pyAn example of an idiom for controling threadsDoug Forthttp://www.dougfort.net"""import threadingclass TestThread(threading.Thread): """ A sample thread class """ def __init__(self): """ Constructor,setting initial variables """ self._stopevent = threading.Event() self._sleepperiod = 1.0 threading.Thread.__init__(self,name="TestThread") def run(self): """ overload of threading.thread.run() main control loop """ print "%s starts" % (self.getname(),) count = 0 while not self._stopevent.isSet(): count += 1 print "loop %d" % (count,) self._stopevent.wait(self._sleepperiod) print "%s ends" % (self.getname(),) def join(self,timeout=None): """ Stop the thread """ self._stopevent.set() threading.Thread.join(self,timeout)if __name__ == "__main__": testthread = TestThread() testthread.start() import time time.sleep(10.0) testthread.join()
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的Python的线程控制类全部内容,希望文章能够帮你解决Python的线程控制类所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)