首页 > 代码库 > MAYA 多线程
MAYA 多线程
‘‘‘Usage:def timerTest(): print ‘Hello World!‘#create and start a timertimer = Timer(30, timerTest, repeat=True)timer.start()#To stop the timertimer.stop()‘‘‘import threadingtry: from maya.utils import executeInMainThreadWithResultexcept: executeInMainThreadWithResult = Noneclass Timer(threading.Thread): def __init__(self, interval, function, args=[], kwargs={}, repeat=True): self.interval = interval self.function = function self.repeat = repeat self.args = args self.kwargs = kwargs self.event = threading.Event() threading.Thread.__init__(self) def run(self): def _mainLoop(): self.event.wait(self.interval) if not self.event.isSet(): if executeInMainThreadWithResult: executeInMainThreadWithResult(self.function, *self.args, **self.kwargs) else: self.function(*self.args, **self.kwargs) if self.repeat: while not self.event.isSet(): _mainLoop() else: _mainLoop() self.stop() def start(self): self.event.clear() threading.Thread.start(self) def stop(self): self.event.set() threading.Thread.__init__(self)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。