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()
相关内容
- Python实现的MAC系统下的剪贴板代码,pythonmac,This is a c
- python方法参数默认值示例,python默认值示例,def boxVolu
- python如何删除文件,文件夹,python删除文件,python删除文
- Python将jpeg或jpg图片转换为png图片,,python的pil库可
- python将png图片转换为jpeg图片,,如下代码使用PIL库将p
- Python判断图片是否是jpeg格式(非扩展名方式),,用扩
- django上传图片并生成缩略图代码示例,,django 处理上传
- python创建临时文件代码,python创建代码,python有一个te
- python UDP 协议通信,pythonudp协议通信,import socke
- python计算GPS两点之间的中间点,python计算GPS两点,impor
评论关闭