Ensure the server termiantes once it is no longer active

Starting a `ThreadedServer` from within a thread, I need to close/terminate the server by calling `close()` on it. However, the current implementation keeps the `ThreadedServer` running, even if its `active` state changes from `True` to `False`.

The following patch fixes this. Note that I had to introduce a `self.listener.settimeout(0.5) `, such that the while loop in `def accept(self):` can check for `self.active == False` from time to time.