def _monitor_event_servers(self): def wrapped_func(): servers = self._get_event_servers() self._update_event_servers(servers) callInGreenThread(wrapped_func) return KeepRunning
def start(self): if self._started: raise RuntimeError("worker has already been started") if not threadable.isInIOThread(): raise RuntimeError("worker can only be started in the IO thread") self._started = True callInGreenThread(self.__run__)
def wrapper(*args, **kw): event = coros.event() def wrapped_func(): try: result = func(*args, **kw) except: event.send_exception(*sys.exc_info()) else: event.send(result) if threadable.isInIOThread(): callInGreenThread(wrapped_func) else: from twisted.internet import reactor reactor.callFromThread(callInGreenThread, wrapped_func) return event
def call_in_green_thread(func, *args, **kw): if threadable.isInIOThread(): callInGreenThread(func, *args, **kw) else: from twisted.internet import reactor reactor.callFromThread(callInGreenThread, func, *args, **kw)