I am implementing a socket server in python. Everything works well except KeyboardInterrupt does not stop my server in the terminal. Any ideas? Thank a lot!
def run(self) -> None:
try:
self.socket.listen()
print(f'$ - Server {self.host}:{self.port} is running.')
while True:
client, address = self.socket.accept()
Thread(target=clientHandler, args=[client, address]).start()
except KeyboardInterrupt:
print('! - Server interrupted.')
when ctrl+c
is pressed it should stop the server but it does not