switch to multiprocessing, attempt to improve KeyboardInterrupt handling (or add it, actually)

This commit is contained in:
Xevion
2021-01-21 11:59:11 -06:00
parent 7185d1d1ae
commit 50ddf83ed7
2 changed files with 19 additions and 10 deletions

View File

@@ -0,0 +1,4 @@
import logging
logging.basicConfig(level=logging.DEBUG,
format='[%(asctime)s] [%(levelname)s] [%(threadName)s] %(message)s')

View File

@@ -1,6 +1,6 @@
import logging
import multiprocessing
import socket
import threading
from server import handler
@@ -21,6 +21,7 @@ clients = []
# Receiving / Listening Function
def receive():
while True:
try:
# Accept Connection
conn, address = server.accept()
logger.info(f"New connection from {address}")
@@ -30,8 +31,12 @@ def receive():
client.request_nickname()
# Start Handling Thread For Client
thread = threading.Thread(target=client.handle, name=client.id[:8])
thread = multiprocessing.Process(target=client.handle, name=client.id[:8])
thread.start()
except KeyboardInterrupt:
logger.info('Server closed by user.')
except Exception as e:
logger.critical(e, exc_info=e)
if __name__ == '__main__':