转: python 定时器 在编写服务进程的时候,往往需要定时落地一些数据,这就需要定时来执行一些操作,然后python中并没有合适的定时器(我没有找到),就自己diy吧。 view sourceprint?[code]import threading,time class Timer(threading.Thread): def __init__(self,fn,args=(),sleep=0,lastDo=True): threading.Thread.__init__(self) self.fn = fn self.args = args ...
by feiyang10086 - Python - 2011-06-03 16:19:06 阅读(3855) 回复(0)
初始化一个定时器,希望在不用的时候可以删除,但是总是不行,代码如下,哪里不对呢~~~ from threading import Timer from time import ctime, sleep class foo: def __init__(self): pass def disconnect(self): self.timer.cancel() print('dead...') def keepAlive(self): print('aliving...') self.timer = Timer(1, self.keepAlive) self.timer.start...
给产品写脚本的时候,发现python居然没有 内置的定时器模块 虽然 while ture:sleep(1);可以解决问题 感觉还是不爽 后来,自己用c写了个定时器模块, 其中涉及调用关系,浪费了不少时间 python-> c-> python
本帖最后由 gdp8899 于 2013-07-11 00:14 编辑
python is是种很特殊的语法,你在其它的语言应该不会见到这样的用法,今天就来说说这个把。 python is 按照自字面的意思就是什么东西是什么的,比如he is a boy,他是一个大男孩,而我们一般在写python程序的时候,也会用到一些判断,有的时候也会用到python is,比如判断下这个字符是否为none。 下面是python is的例子,比如我们来判断下一个字符串。 a = 'abc' if a is not None: print 'a is not none' 输出的结果是 a is not ...
#!/urs/bin/python contact = {} contact_list = [] select = ['1.insert','2.delete'] for i in select: print i print 'what\'s your choise:' get = raw_input('1 or 2') if get == 1: test = 1 while test==1: contact['name'] = raw_input("please input name: ") contact['phone'] = raw_input("please input phone number: ") contact_list.append(contact.copy()) go_on = raw_input("continue?\n") ...
好好学python,以后要养家吃饭的!!! 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/89259/showart_1885773.html