def runEventLoop(self, timeout=10, timeoutNormal=False): eventloop.thread_pool_init() eventloop._eventloop.quit_flag = False eventloop._eventloop.idle_queue.quit_flag = False eventloop._eventloop.urgent_queue.quit_flag = False try: self.hadToStopEventLoop = False timeout_handle = eventloop.add_timeout(timeout, self.stopEventLoop, "Stop test event loop") eventloop._eventloop.quit_flag = False eventloop._eventloop.loop() if self.hadToStopEventLoop and not timeoutNormal: raise HadToStopEventLoop() else: timeout_handle.cancel() finally: eventloop.thread_pool_quit()
def action(self): starttime = time.time() from miro import httpclient from miro.dl_daemon import download download.shutdown() httpclient.stop_thread() eventloop.thread_pool_quit() for thread in threading.enumerate(): if (thread != threading.currentThread() and thread.getName() != "MainThread" and not thread.isDaemon()): thread.join() endtime = starttime + DAEMONIC_THREAD_TIMEOUT for thread in threading.enumerate(): if (thread != threading.currentThread() and thread.getName() != "MainThread"): timeout = endtime - time.time() if timeout <= 0: break thread.join(timeout) c = ShutDownResponseCommand(self.daemon) c.send(callback=self.response_sent) self.daemon.shutdown = True