关闭python_如何关闭python s

您的问题不明确-如果您通过shell(即python myscript.py)运行服务器,只需按crtl + C。

如果要使用代码优雅地关闭它,必须确定某个条件、点或异常才能将其调用shutdown。您可以添加一个块并调用httpd.shutdown()-因为The first class, HTTPServer, is a SocketServer.TCPServer subclass, and

therefore implements the SocketServer.BaseServer interface. It creates

and listens at the HTTP socket, dispatching the requests to a handler.

因此BaseServer有一个方法

例如:import os

from http.server import SimpleHTTPRequestHandler, HTTPServer

os.chdir('c:/users/owner/desktop/tom/tomsEnyo2.5-May27')

server_address = ('', 8000)

try:

httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)

httpd.serve_forever()

except Exception:

httpd.shutdown()

有用的相关问题-

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值