Here I have some abstract code that I need to work.
>>> s0 = Server(port='5000', handle=print)
>>> s0.stop()
>>> # Starting a second server with another port seems OK.
>>> s1 = Server(port='5001', handle=print)
>>> s1.stop()
>>> # This will raise Exception, because port '5000' is still busy by a first server(s0 object).
>>> # I have to exit python process, to release port.
>>> # P.S. deleting an object does not change anything.
>>> s2 = Server(port='5000', handle=print)
I've tried Flask. I've tried SimpleXMLRPCServer: How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass?
Even if it is not raising Exception, the (s2 object) does not accept requests, they are going nowhere, not returning a status or anything.
How can I create a server on port '5000' for example, close this server and create it again when needed. Is it possible with python?