serve_forever在对面收通知发请求前开始工作就行
看代码似乎不用太担心:
def serve_forever(self, poll_interval=0.5):
"""Handle one request at a time until shutdown.
Polls for shutdown every poll_interval seconds. Ignores
self.timeout. If you need to do periodic tasks, do them in
another thread.
"""
self.__is_shut_down.clear()
try:
# XXX: Consider using another file descriptor or connecting to the
# socket to wake this up instead of polling. Polling reduces our
# responsiveness to a shutdown request and wastes cpu at all other
# times.
with _ServerSelector() as selector:
selector.register(self, selectors.EVENT_READ)
while not self.__shutdown_request:
ready = selector.select(poll_interval)
# bpo-35017: shutdown() called during select(), exit immediately.
if self.__shutdown_request:
break
if ready:
self._handle_request_noblock()
self.service_actions()
finally:
self.__shutdown_request = False
self.__is_shut_down.set()
【 在 JulyClyde 的大作中提到: 】
: 标 题: Re: 如何自己开一个http服务器并通知别人来访问?
: 发信站: 水木社区 (Fri Jun 21 11:54:00 2024), 转信
:
:
: 【 在 vwx 的大作中提到: 】
: : 真走火入魔
: : 搜到的代码
: : import http.server
: : import socketserver
: : PORT = 8080
: : Handler = http.server.SimpleHTTPRequestHandler
: : with socketserver.TCPServer(("", PORT), Handler) as httpd:
: : ### 写通知
: : httpd.serve_forever()
: 这不就是我说的那种明显的错误么?
:
: --
:
: ※ 来源:·水木社区 mysmth.net·[FROM: 139.227.19.*]
--
FROM 61.149.143.*