From 66cde7c51a871a86cf8667adf4bd1d03e9b98eb1 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 29 Mar 2022 14:45:47 -0700 Subject: bpo-42340: Document issues around KeyboardInterrupt (GH-23255) Update documentation to note that in some circumstances, KeyboardInterrupt may cause code to enter an inconsistent state. Also document sample workaround to avoid KeyboardInterrupt, if needed. (cherry picked from commit d0906c90fcfbc4cfb9bb963eaa6bb152dd543b56) Co-authored-by: benfogle --- Doc/library/exceptions.rst | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Doc/library/exceptions.rst') diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index 2f97bb8131..50a3ff3452 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -246,6 +246,15 @@ The following exceptions are the exceptions that are usually raised. accidentally caught by code that catches :exc:`Exception` and thus prevent the interpreter from exiting. + .. note:: + + Catching a :exc:`KeyboardInterrupt` requires special consideration. + Because it can be raised at unpredictable points, it may, in some + circumstances, leave the running program in an inconsistent state. It is + generally best to allow :exc:`KeyboardInterrupt` to end the program as + quickly as possible or avoid raising it entirely. (See + :ref:`handlers-and-exceptions`.) + .. exception:: MemoryError -- cgit v1.2.1