New submission from Tony <[email protected]>:
Currently calling BaseServer's shutdown() function will not make
serve_forever() return immediately from it's select().
I suggest adding a new function called server_shutdown() that will make
serve_forever() shutdown immediately.
Then in TCPServer(BaseServer) all we need to do is call
self.socket.shutdown(socket.SHUT_RDWR) in server_shutdown()'s implementation.
To test this I made a simple script:
import threading
import time
from functools import partial
from http.server import HTTPServer, SimpleHTTPRequestHandler
def serve_http(server):
server.serve_forever(poll_interval=2.5)
def main():
with HTTPServer(('', 8000), SimpleHTTPRequestHandler) as server:
t = threading.Thread(target=partial(serve_http, server))
t.start()
time.sleep(3)
start = time.time()
print('shutdown')
server.shutdown()
print(f'time it took: {time.time() - start}')
if __name__ == "__main__":
main()
----------
components: Library (Lib)
messages: 372194
nosy: tontinton
priority: normal
severity: normal
status: open
title: BaseServer's server_forever() shutdown immediately when calling
shutdown()
type: enhancement
versions: Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41093>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com