fix: исправить зависание при Ctrl+C
- signal_handler вызывает shutdown() который блокируется - Убран sys.exit(0) из signal handler - serve_forever() завершается через KeyboardInterrupt - finally закрывает сокет корректно
This commit is contained in:
@@ -40,9 +40,8 @@ def signal_handler(sig, frame):
|
|||||||
"""Handle Ctrl+C gracefully."""
|
"""Handle Ctrl+C gracefully."""
|
||||||
print("\n👋 Shutting down...")
|
print("\n👋 Shutting down...")
|
||||||
if httpd:
|
if httpd:
|
||||||
|
# Use shutdown() to stop serve_forever()
|
||||||
httpd.shutdown()
|
httpd.shutdown()
|
||||||
httpd.server_close()
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -75,8 +74,9 @@ def main():
|
|||||||
╚══════════════════════════════════════════════════════════╝
|
╚══════════════════════════════════════════════════════════╝
|
||||||
""")
|
""")
|
||||||
|
|
||||||
with socketserver.TCPServer((args.host, args.port), CustomHandler) as httpd:
|
httpd = socketserver.TCPServer((args.host, args.port), CustomHandler)
|
||||||
print(f"🚀 Server started on http://{args.host}:{args.port}")
|
print(f"🚀 Server started on http://{args.host}:{args.port}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|||||||
Reference in New Issue
Block a user