python子线程调用主线程的控件显示_python,从timer callb调用主线程上的方法

本文介绍了一种在Python中使用repeater类来实现在子线程中调用主线程控件显示的方法。repeater类包含start、stop、serviceall等方法,能够处理多个定时任务,并在主线程中执行。通过调整MAXBLOCKINGPERIOD参数,可以平衡服务处理和线程等待时间,确保程序的响应速度。示例代码演示了如何创建和管理repeater实例,以及如何在主线程中使用sleep方法来控制执行流程。
摘要由CSDN通过智能技术生成

我也需要这么做,我做的是:import time

MAXBLOCKINGSECONDS=5 #maximum time that a new task will have to wait before it's presence in the queue gets noticed.

class repeater:

repeatergroup=[] #our only static data member it holds the current list of the repeaters that need to be serviced

def __init__(self,callback,interval):

self.callback=callback

self.interval=abs(interval) #because negative makes no sense, probably assert would be better.

self.reset()

self.processing=False

def reset(self):

self.nextevent=time.time()+self.interval

def whennext(self):

return self.nextevent-time.time() #time until next event

def service(self):

if time.time()>=self.nextevent:

if self.processing=True: #or however you want to be re-entrant safe or thread safe

return 0

self.processin

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值