Stop the server and exit when there are no more clients.
(reason: str = "")
| 619 | |
| 620 | |
| 621 | def trigger_shutdown(reason: str = ""): |
| 622 | """Stop the server and exit when there are no more clients.""" |
| 623 | if reason: |
| 624 | print(reason) |
| 625 | if shutdown_event.is_set(): |
| 626 | return |
| 627 | shutdown_event.set() |
| 628 | |
| 629 | def _stop(): |
| 630 | # Give the watcher loop a moment to exit |
| 631 | time.sleep(0.2) |
| 632 | try: |
| 633 | socketio.stop() |
| 634 | except Exception: |
| 635 | pass |
| 636 | # Ensure process exits |
| 637 | sys.exit(0) |
| 638 | |
| 639 | threading.Thread(target=_stop, daemon=True).start() |
| 640 | |
| 641 | |
| 642 | HTML_TEMPLATE = """ |
no test coverage detected