1 Star 8 Fork 4

不懂d叛逆/pyccjh

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ccjhTimer.py 948 Bytes
一键复制 编辑 原始数据 按行查看 历史
不懂d叛逆 提交于 2015-02-06 17:03 +08:00 . \r\n替换为\n
# -*- coding: utf-8 -*-
'''
Created on 2013-5-30
定时器
@author: 不懂d叛逆
'''
import threading, time
class timer(threading.Thread):
def __init__(self, delay, func, args = ()):
self.__delay = delay
threading.Thread.__init__(self)
self.endless = True
self.__func = func
self.__args = args
self.start()
return
def run(self):
while(self.endless):
time.sleep(self.__delay)
if self.endless:
if len(self.__args) > 0:
self.__func(self.__args)
else:
self.__func()
return
def stop(self):
self.endless = False
self.join(0.1)
if self._stopped == False:
self._stop()
class onceTimer(threading.Thread):
def __init__(self, delay, func, args = ()):
self.__delay = delay
threading.Thread.__init__(self)
self.__func = func
self.__args = args
self.start()
return
def run(self):
time.sleep(self.__delay)
if len(self.__args) > 0:
self.__func(self.__args)
else:
self.__func()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/panlizzx/pyccjh.git
git@gitee.com:panlizzx/pyccjh.git
panlizzx
pyccjh
pyccjh
master

搜索帮助