[New-bugs-announce] [issue41093] BaseServer's server_forever() shutdown immediately when calling shutdown()

Tony report at bugs.python.org
Tue Jun 23 15:01:13 EDT 2020


New submission from Tony <tony.solomonik at gmail.com>:

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 <report at bugs.python.org>
<https://bugs.python.org/issue41093>
_______________________________________


More information about the New-bugs-announce mailing list