Issue 23430: socketserver.BaseServer.handle_error() should not catch exiting exceptions (original) (raw)

Created on 2015-02-10 03:34 by martin.panter, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
socketserver-exit.patch martin.panter,2015-02-10 03:34 review
socketserver-exit.v2.patch martin.panter,2015-02-15 05:22 review
socketserver-exit.v3.patch martin.panter,2015-03-28 04:59 review
socketserver-exit.v4.patch martin.panter,2015-03-28 05:04 review
socketserver-exit.v5.patch martin.panter,2016-02-12 23:06 review
socketserver-exit.v6.patch martin.panter,2016-02-19 04:24 review
Messages (7)
msg235662 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-02-10 03:34
I propose changing the socket servers to not suppress exceptions that are meant to exit the interpreter. This is most applicable to single threaded servers, but my patch does the same thing for multithreading servers. It no longer catches exceptions that are not derived from the Exception class, such as KeyboardInterrupt and SystemExit. The shutdown_request() method is still called in all cases though. I also added a test for the forking server’s handle_error() method.
msg236022 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-02-15 05:22
Looking at this again, I think I should make the forking server’s handle_error() method only be called for Exception subclasses as well. So I am posting a new patch that also does this.
msg239454 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-03-28 04:59
Patch v3: * Changed the structure of exception handling for the forking server so that there is only one os._exit(status) call site * Rewrote tests to log results to a temporary file. This avoids sending a string of code to a Python subprocess. I use threading.Event and os.waitpid() to synchronize. * Tests now call the handle_request() public API, and create a trivial TCP connection to trigger a request. * Added doc string explaining simple_subprocess() Let me know what you think.
msg239455 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-03-28 05:04
Oops I forgot to refresh the patch. Patch v4 also closes the server in the tests.
msg260209 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-02-12 23:06
Here is an updated version for 3.6. I also wrote an entry for What’s New. It seems my change could help people trying to make a single-threaded server quit the server loop (Issue 13749).
msg260503 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-02-19 04:24
Thanks for the reivew Berker. I have merged the patch with recent changes and updated according to your comments.
msg260605 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-02-21 11:01
New changeset d500d1a9615f by Martin Panter in branch 'default': Issue #23430: Stop socketserver from catching SystemExit etc from handlers https://hg.python.org/cpython/rev/d500d1a9615f
History
Date User Action Args
2022-04-11 14:58:12 admin set github: 67618
2016-02-22 09:07:41 martin.panter set status: open -> closedresolution: fixedstage: commit review -> resolved
2016-02-21 11:25:51 martin.panter link issue25139 superseder
2016-02-21 11:01:43 python-dev set nosy: + python-devmessages: +
2016-02-19 12:46:07 berker.peksag set stage: patch review -> commit review
2016-02-19 04:24:04 martin.panter set files: + socketserver-exit.v6.patchmessages: +
2016-02-12 23:06:30 martin.panter set files: + socketserver-exit.v5.patchmessages: + versions: + Python 3.6, - Python 3.5
2015-03-28 05:04:26 martin.panter set files: + socketserver-exit.v4.patchmessages: +
2015-03-28 04:59:49 martin.panter set files: + socketserver-exit.v3.patchmessages: +
2015-02-28 17:39:29 serhiy.storchaka set nosy: + pitrou
2015-02-15 05:22:12 martin.panter set files: + socketserver-exit.v2.patchmessages: +
2015-02-14 23:09:07 berker.peksag set nosy: + berker.peksagstage: patch review
2015-02-10 03:34:08 martin.panter create