码迷,mamicode.com
首页 > 编程语言 > 详细

MAYA 多线程

时间:2014-08-03 04:39:44      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   art   cti   ar   div   

‘‘‘
Usage:
def timerTest():
    print ‘Hello World!‘

#create and start a timer
timer = Timer(30, timerTest, repeat=True)
timer.start()

#To stop the timer
timer.stop()
‘‘‘

import threading

try:
    from maya.utils import executeInMainThreadWithResult
except:
    executeInMainThreadWithResult = None

class 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)

MAYA 多线程,布布扣,bubuko.com

MAYA 多线程

标签:style   blog   color   io   art   cti   ar   div   

原文地址:http://www.cnblogs.com/jonn/p/3887906.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!