diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py index 122430e362d..df56830f055 100644 --- a/Lib/SocketServer.py +++ b/Lib/SocketServer.py @@ -229,6 +229,9 @@ class BaseServer: # shutdown request and wastes cpu at all other times. r, w, e = _eintr_retry(select.select, [self], [], [], poll_interval) + # bpo-35017: shutdown() called during select(), exit immediately. + if self.__shutdown_request: + break if self in r: self._handle_request_noblock() finally: diff --git a/Misc/NEWS.d/next/Library/2018-10-26-00-11-21.bpo-35017.6Ez4Cv.rst b/Misc/NEWS.d/next/Library/2018-10-26-00-11-21.bpo-35017.6Ez4Cv.rst new file mode 100644 index 00000000000..5682717adf7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-10-26-00-11-21.bpo-35017.6Ez4Cv.rst @@ -0,0 +1,3 @@ +:meth:`socketserver.BaseServer.serve_forever` now exits immediately if it's +:meth:`~socketserver.BaseServer.shutdown` method is called while it is +polling for new events.