def start_new_thread(function, args, kwargs={}, name=None): def threadFunc(threadId, function=function, args=args, kwargs=kwargs): try: try: function(*args, **kwargs) except SystemExit: pass finally: _remove_thread_id(threadId) global _nextThreadId _threadsLock.acquire() try: threadId = _nextThreadId _nextThreadId += 1 if name is None: name = 'PythonThread-%s' % (threadId) thread = pm.PythonThread(threadFunc, [threadId], name, name) thread.setPythonData(threadId) _threads[threadId] = (thread, {}, None) thread.start(pm.TPNormal, False) return threadId finally: _threadsLock.release()
def __init__(self, group=None, target=None, name=None, args=(), kwargs={}): ThreadBase.__init__(self) assert group is None self.__target = target self.__args = args self.__kwargs = kwargs current = current_thread() self.__dict__['daemon'] = current.daemon self.__dict__['name'] = name self.__thread = pm.PythonThread(self.run, None, name, name) threadId = _thread._add_thread(self.__thread, weakref.proxy(self)) self.__dict__['ident'] = threadId
def __init__(self, group=None, target=None, name=None, args=(), kwargs={}): ThreadBase.__init__(self) self.__target = target self.__args = args self.__kwargs = kwargs if not name: import threading2 name = threading2._newname() current = current_thread() self.__dict__['daemon'] = current.daemon self.__dict__['name'] = name self.__thread = pm.PythonThread(self.run, None, name, name) threadId = _thread._add_thread(self.__thread, weakref.proxy(self)) self.__dict__['ident'] = threadId return