httpd.serve_forever()
Once started, the service will run for ever until you shut down your session. When starting another instance of the script, the running service has still opened the listening port so that trying to open it is refused with the error 10048 /
WSAEADDRINUSE
.
If you want to execute the script again you have to signal the running service to stop and close the socket. This requires implementing your own version of
serve_forever()
which can leave the service loop upon some kind of signal and close socket. See also this SO thread:
python - How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass? - Stack Overflow[
^]