mirror of
https://github.com/Xevion/tcp-chat.git
synced 2025-12-06 05:16:45 -06:00
switch to multiprocessing, attempt to improve KeyboardInterrupt handling (or add it, actually)
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
import logging
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
format='[%(asctime)s] [%(levelname)s] [%(threadName)s] %(message)s')
|
||||
|
||||
@@ -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__':
|
||||
|
||||
Reference in New Issue
Block a user