打开python服务器

发布于 2025-02-09 02:16:26 字数 903 浏览 2 评论 0原文

在这里,我有一些我需要工作的抽象代码。

>>> 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)

我尝试了烧瓶。 我尝试了SumplexmlrpcServer:

即使没有引起异常,(S2对象)不接受请求,它们无处不在,不返回状态或任何东西。

例如,如何在端口“ 5000”上创建服务器,关闭此服务器并在需要时再次创建它。 Python有可能吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文