summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/__main__.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-09-06 20:25:19 (GMT)
committerGitHub <noreply@github.com>2024-09-06 20:25:19 (GMT)
commit5c3078d6e597c7e50b3b0da37f493e2dfca17a6a (patch)
treec8f16cbf540fee5b7527d51b3b9ff7ed9c8b065e /Lib/asyncio/__main__.py
parent66b15381f187f00f0fd91575f9f11e14bfddeeca (diff)
downloadcpython-5c3078d6e597c7e50b3b0da37f493e2dfca17a6a.zip
cpython-5c3078d6e597c7e50b3b0da37f493e2dfca17a6a.tar.gz
cpython-5c3078d6e597c7e50b3b0da37f493e2dfca17a6a.tar.bz2
[3.13] gh-120221: Support KeyboardInterrupt in asyncio REPL (GH-123795) (#123799)
This switches the main pyrepl event loop to always be non-blocking so that it can listen to incoming interruptions from other threads. This also resolves invalid display of exceptions from other threads (gh-123178). This also fixes freezes with pasting and an active input hook. (cherry picked from commit 033510e11dff742d9626b9fd895925ac77f566f1) Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/asyncio/__main__.py')
-rw-r--r--Lib/asyncio/__main__.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/asyncio/__main__.py b/Lib/asyncio/__main__.py
index 111b7d9..5120140 100644
--- a/Lib/asyncio/__main__.py
+++ b/Lib/asyncio/__main__.py
@@ -127,6 +127,15 @@ class REPLThread(threading.Thread):
loop.call_soon_threadsafe(loop.stop)
+ def interrupt(self) -> None:
+ if not CAN_USE_PYREPL:
+ return
+
+ from _pyrepl.simple_interact import _get_reader
+ r = _get_reader()
+ if r.threading_hook is not None:
+ r.threading_hook.add("") # type: ignore
+
if __name__ == '__main__':
sys.audit("cpython.run_stdin")
@@ -184,6 +193,7 @@ if __name__ == '__main__':
keyboard_interrupted = True
if repl_future and not repl_future.done():
repl_future.cancel()
+ repl_thread.interrupt()
continue
else:
break