博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 结合 schedule 和thread 实现触发式周期调用某函数(更新数据)
阅读量:2397 次
发布时间:2019-05-10

本文共 1832 字,大约阅读时间需要 6 分钟。

#! /usr/bin/env python    # This Python file uses the following encoding: utf-8'''Created on Nov 18, 2013@author: root'''from threading import Threadimport time, sched             schedule = sched.scheduler(time.time, time.sleep)         class test(Thread):        time_available_flag=True    opt=0           def __init__(self):        Thread.__init__(self)             def perform_command(self, inc):                   self.write_xml()            def timming_exe(self, inc = 20):                               schedule.enter(inc, 0, self.perform_command, ( inc,))                         schedule.run()                def write_xml(self):        print('write xml to file opt %s'%test.opt)          test.time_available_flag=True          print("schedu finished",time.time())        print('some func  called  here   ','opt  ------------,写入数据',self.__class__.opt)            def run(self):        print("schedu started",time.time())        self.timming_exe()                        def whether_write_xml(self,count):        #         print(time.time())        if count>0:            self.__class__.opt=self.__class__.opt+1            print("time_available_flag",self.__class__.time_available_flag,self.__class__.opt)            if self.__class__.time_available_flag:                self.__class__.time_available_flag=False                print("first start ",self.__class__.time_available_flag)                self.start()#                print(time.time())#         print(time.time())        return count  if __name__ == '__main__':        x=test()    print(x.whether_write_xml(1))    #     time.sleep(2)        print(x.whether_write_xml(2))#     time.sleep(3)    print(x.whether_write_xml(3))#     time.sleep(5)        print(x.time_available_flag)        xx=test()    print(xx.whether_write_xml(4))    print(xx.whether_write_xml(5))

转载地址:http://mmyob.baihongyu.com/

你可能感兴趣的文章
ARM保存中断时,为什么使用“sub lr, lr, #4”
查看>>
Makefile中.PHONY的含义
查看>>
韦东山视频实验之Input子系统分析之一
查看>>
韦东山视频实验之Input子系统分析之二
查看>>
韦东山视频实验之触摸屏
查看>>
dma_alloc_writecombine
查看>>
韦东山视频之LCD驱动(Mini2440 X35)
查看>>
韦东山视频实验之USB鼠标驱动
查看>>
韦东山视频实验之USB鼠标驱动—OOPS错误分析
查看>>
python异常处理
查看>>
python创建字典
查看>>
python列表元组的操作
查看>>
python基础之元组、文件操作、编码、函数、变量
查看>>
两个路径下的iptables的区别
查看>>
wsgi.py的详解
查看>>
python中setting.py详解
查看>>
python的__init__.py
查看>>
最新pycharm破解(亲试有效)
查看>>
python中的变量怎样开辟内存
查看>>
tomcat端口号直接跳转到项目首页
查看>>