This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tontinton
Recipients tontinton
Date 2020-06-23.19:01:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1592938873.08.0.742314253675.issue41093@roundup.psfhosted.org>
In-reply-to
Content
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()
History
Date User Action Args
2020-06-23 19:01:13tontintonsetrecipients: + tontinton
2020-06-23 19:01:13tontintonsetmessageid: <1592938873.08.0.742314253675.issue41093@roundup.psfhosted.org>
2020-06-23 19:01:13tontintonlinkissue41093 messages
2020-06-23 19:01:12tontintoncreate