def invokeTarget(self, target): """Run a target in a new RepositoryThread w/a new repository view""" thread = RepositoryThread( name=str(self.itsPath), target=target, args=(fork_item(self),) ) thread.setDaemon(True) # main thread can exit even if this one hasn't thread.start()
def invokeTarget(self, target): """Run a target in a new RepositoryThread w/a new repository view""" thread = RepositoryThread(name=str(self.itsPath), target=target, args=(fork_item(self), )) thread.setDaemon(True) # main thread can exit even if this one hasn't thread.start()
def run_reactor(in_thread=True): """Safely run the Twisted reactor""" global _reactor_thread from osaf.framework.twisted import TwistedThreadPool # initializes threads from twisted.python import threadpool threadpool.ThreadPool = TwistedThreadPool.RepositoryThreadPool from twisted.internet import reactor if not in_thread: if reactor.running: raise AssertionError("Reactor is already running") # enable repeated reactor runs def _del_pool(): reactor.threadpool = None for evt in reactor.crash, reactor.disconnectAll, _del_pool: reactor.addSystemEventTrigger('during', 'shutdown', evt) reactor.run(0) return import sys if _reactor_thread is None: if threading.currentThread().getName() != "MainThread": raise AssertionError( "can't start reactor thread except from the main thread") limbo = [1] reactor.addSystemEventTrigger('before', 'startup', limbo.pop) _reactor_thread = RepositoryThread(name="reactor", target=run_reactor, args=(False, )) _reactor_thread.setDaemon(True) # let main thread exit even if running _reactor_thread.start() while limbo and _reactor_thread.isAlive(): pass # wait for reactor to start or thread to die (e.g. w/error) if not _reactor_thread.isAlive(): _reactor_thread = None
def run_reactor(in_thread=True): """Safely run the Twisted reactor""" global _reactor_thread from osaf.framework.twisted import TwistedThreadPool # initializes threads from twisted.python import threadpool threadpool.ThreadPool = TwistedThreadPool.RepositoryThreadPool from twisted.internet import reactor if not in_thread: if reactor.running: raise AssertionError("Reactor is already running") # enable repeated reactor runs def _del_pool(): reactor.threadpool = None for evt in reactor.crash, reactor.disconnectAll, _del_pool: reactor.addSystemEventTrigger('during', 'shutdown', evt) reactor.run(0) return import sys if _reactor_thread is None: if threading.currentThread().getName() != "MainThread": raise AssertionError( "can't start reactor thread except from the main thread" ) limbo = [1] reactor.addSystemEventTrigger('before', 'startup', limbo.pop) _reactor_thread = RepositoryThread( name="reactor", target=run_reactor, args=(False,) ) _reactor_thread.setDaemon(True) # let main thread exit even if running _reactor_thread.start() while limbo and _reactor_thread.isAlive(): pass # wait for reactor to start or thread to die (e.g. w/error) if not _reactor_thread.isAlive(): _reactor_thread = None