Python的线程控制类,Python线程控制类,下面是一个基础的pyth
Python的线程控制类,Python线程控制类,下面是一个基础的pyth
下面是一个基础的python线程控制类
#!/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()
相关内容
- 打印列表内容,列表内容,values = [4,
- python 爬虫 下载妹子图片,,#coding:utf-
- python实现单链表,python实现单链,#coding:utf-
- Python发送带附件的SMTP邮件代码,pythonsmtp,利用python的
- Python实现http文件下载,python实现文件下载,在自动化脚
- 使用xlrd读取excel并返回json,xlrd读取exceljson,# -*- coding
- 深度搜索+命令模式 解数独,深度命令模式解数,def fl
- 发送邮件,,#!/usr/bin/e
- urllib2使用代理服务器,urllib2代理服务器,本代码演示了
- 批量修改图片大小Python代码,,# -*- coding
评论关闭