| 889 | self._sth.start() |
| 890 | |
| 891 | def serve_forever(self): |
| 892 | # we could join on the threads, but join blocks all interrupts (including |
| 893 | # ctrl+c, so just spin here |
| 894 | # noinspection PyBroadException |
| 895 | try: |
| 896 | def sig_manager(sig, callstack): |
| 897 | self.stop() |
| 898 | self._log.info('*** signal %d received.' % sig) |
| 899 | return signal.SIG_IGN |
| 900 | prev_handler = signal.signal(signal.SIGINT, sig_manager) |
| 901 | except Exception: |
| 902 | # signal.pause() is missing for Windows; wait 1ms and loop instead |
| 903 | pass |
| 904 | except KeyboardInterrupt: |
| 905 | pass |
| 906 | while self._alive: |
| 907 | try: |
| 908 | time.sleep(1) |
| 909 | except Exception: |
| 910 | self._alive = False |
| 911 | self._log.debug(' ** serve_forever() quitting') |
| 912 | |
| 913 | def stop(self): |
| 914 | global clients |