| 2805 | threading.Thread.start(self) |
| 2806 | |
| 2807 | def run(self): |
| 2808 | if not self._in_context: |
| 2809 | raise ValueError( |
| 2810 | 'ThreadedEchoServer must be used as a context manager') |
| 2811 | self.sock.settimeout(1.0) |
| 2812 | self.sock.listen(5) |
| 2813 | self.active = True |
| 2814 | if self.flag: |
| 2815 | # signal an event |
| 2816 | self.flag.set() |
| 2817 | while self.active: |
| 2818 | try: |
| 2819 | newconn, connaddr = self.sock.accept() |
| 2820 | if support.verbose and self.chatty: |
| 2821 | sys.stdout.write(' server: new connection from ' |
| 2822 | + repr(connaddr) + '\n') |
| 2823 | handler = self.ConnectionHandler(self, newconn, connaddr) |
| 2824 | handler.start() |
| 2825 | handler.join() |
| 2826 | except TimeoutError as e: |
| 2827 | if support.verbose: |
| 2828 | sys.stdout.write(f' connection timeout {e!r}\n') |
| 2829 | except KeyboardInterrupt: |
| 2830 | self.stop() |
| 2831 | except BaseException as e: |
| 2832 | if support.verbose and self.chatty: |
| 2833 | sys.stdout.write( |
| 2834 | ' connection handling failed: ' + repr(e) + '\n') |
| 2835 | |
| 2836 | self.close() |
| 2837 | |
| 2838 | def close(self): |
| 2839 | if self.sock is not None: |