def _stop(self, r=None): assert thread.get_ident() == self.ident connections = list(self.single_sockets) for connection in connections: try: connection.close() except: pass reactor.suggestThreadPoolSize(0) try: reactor.stop() except RuntimeError: # exceptions.RuntimeError: can't stop reactor that isn't running pass
def listen_forever(self, doneflag=None): """Main event processing loop for RawServer. RawServer listens until the doneFlag is set by some other thread. The doneFlag tells all threads to clean-up and then exit.""" if not doneflag: doneflag = DeferredEvent() assert isinstance(doneflag, DeferredEvent) self.doneflag = doneflag if not self.associated: self.associate_thread() if self.listened: Exception( _("listen_forever() should only be called once per reactor.")) if main_thread == thread.get_ident() and not self.sigint_installed: self.install_sigint_handler() if is_iocpreactor and main_thread == thread.get_ident(): def pulse(): self.add_task(1, pulse) pulse() reactor.callLater(0, self.doneflag.addCallback, self._safestop) self.listened = True reactor.suggestThreadPoolSize(3) if profile: self.prof.enable() if noSignals: reactor.run(installSignalHandlers=False) else: reactor.run() if profile: self.prof.disable() st = Stats(self.prof.getstats()) st.sort() f = open(prof_file_name, 'wb') st.dump(file=f)
def listen_forever(self, doneflag=None): """Main event processing loop for RawServer. RawServer listens until the doneFlag is set by some other thread. The doneFlag tells all threads to clean-up and then exit.""" if not doneflag: doneflag = DeferredEvent() assert isinstance(doneflag, DeferredEvent) self.doneflag = doneflag if not self.associated: self.associate_thread() if self.listened: Exception(_("listen_forever() should only be called once per reactor.")) if main_thread == thread.get_ident() and not self.sigint_installed: self.install_sigint_handler() if is_iocpreactor and main_thread == thread.get_ident(): def pulse(): self.add_task(1, pulse) pulse() reactor.callLater(0, self.doneflag.addCallback, self._safestop) self.listened = True reactor.suggestThreadPoolSize(3) if profile: self.prof.enable() if noSignals: reactor.run(installSignalHandlers=False) else: reactor.run() if profile: self.prof.disable() st = Stats(self.prof.getstats()) st.sort() f = open(prof_file_name, 'wb') st.dump(file=f)