| 2526 | threading.Thread.start(self) |
| 2527 | |
| 2528 | def run(self): |
| 2529 | if not self._in_context: |
| 2530 | raise ValueError( |
| 2531 | 'ThreadedEchoServer must be used as a context manager') |
| 2532 | self.sock.settimeout(1.0) |
| 2533 | self.sock.listen(5) |
| 2534 | self.active = True |
| 2535 | if self.flag: |
| 2536 | # signal an event |
| 2537 | self.flag.set() |
| 2538 | while self.active: |
| 2539 | try: |
| 2540 | newconn, connaddr = self.sock.accept() |
| 2541 | if support.verbose and self.chatty: |
| 2542 | sys.stdout.write(' server: new connection from ' |
| 2543 | + repr(connaddr) + '\n') |
| 2544 | handler = self.ConnectionHandler(self, newconn, connaddr) |
| 2545 | handler.start() |
| 2546 | handler.join() |
| 2547 | except TimeoutError as e: |
| 2548 | if support.verbose: |
| 2549 | sys.stdout.write(f' connection timeout {e!r}\n') |
| 2550 | except KeyboardInterrupt: |
| 2551 | self.stop() |
| 2552 | except BaseException as e: |
| 2553 | if support.verbose and self.chatty: |
| 2554 | sys.stdout.write( |
| 2555 | ' connection handling failed: ' + repr(e) + '\n') |
| 2556 | |
| 2557 | self.close() |
| 2558 | |
| 2559 | def close(self): |
| 2560 | if self.sock is not None: |