[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

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

The Wayback Machine - https://web.archive.org/web/20210124095455/https://bugs.python.org/issue23430

Issue23430

classification
Title: socketserver.BaseServer.handle_error() should not catch exiting exceptions
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, martin.panter, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2015-02-10 03:34 by martin.panter, last changed 2016-02-22 09:07 by martin.panter. 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) * 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) * 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) * 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) * 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) * 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) * 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) 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
2016-02-22 09:07:41martin.pantersetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2016-02-21 11:25:51martin.panterlinkissue25139 superseder
2016-02-21 11:01:43python-devsetnosy: + python-dev
messages: + msg260605
2016-02-19 12:46:07berker.peksagsetstage: patch review -> commit review
2016-02-19 04:24:04martin.pantersetfiles: + socketserver-exit.v6.patch

messages: + msg260503

2016-02-12 23:06:30martin.pantersetfiles: + socketserver-exit.v5.patch

messages: + msg260209
versions: + Python 3.6, - Python 3.5

2015-03-28 05:04:26martin.pantersetfiles: + socketserver-exit.v4.patch

messages: + msg239455

2015-03-28 04:59:49martin.pantersetfiles: + socketserver-exit.v3.patch

messages: + msg239454

2015-02-28 17:39:29serhiy.storchakasetnosy: + pitrou
2015-02-15 05:22:12martin.pantersetfiles: + socketserver-exit.v2.patch

messages: + msg236022

2015-02-14 23:09:07berker.peksagsetnosy: + berker.peksag

stage: patch review

2015-02-10 03:34:08martin.pantercreate