aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/asyncio/__main__.py
diff options
context:
space:
mode:
authorRémi Lapeyre <remi.lapeyre@lenstra.fr>2024-03-01 20:39:16 +0100
committerGitHub <noreply@github.com>2024-03-01 11:39:16 -0800
commitb5949eac6220ee8002971b5e7026432ac7990c74 (patch)
tree31ce0e7194306baa3afdfba3b3fcc2584aeb7aef /Lib/asyncio/__main__.py
parente6e35327d87e5456ba2178915e4f523a42051d4b (diff)
downloadcpython-b5949eac6220ee8002971b5e7026432ac7990c74.tar.gz
cpython-b5949eac6220ee8002971b5e7026432ac7990c74.zip
gh-84995: Run sys.__interactivehook__() on asyncio REPL startup (#20517)
This makes the asyncio REPL (`python -m asyncio`) more usable and similar to the regular REPL. This exposes register_readline() as a top-level function in site.py, but it's intentionally undocumented. Co-authored-by: Carol Willing <carolcode@willingconsulting.com> Co-authored-by: Itamar Oren <itamarost@gmail.com>
Diffstat (limited to 'Lib/asyncio/__main__.py')
-rw-r--r--Lib/asyncio/__main__.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/asyncio/__main__.py b/Lib/asyncio/__main__.py
index 18bb87a5bc4..cbc1d7c93ef 100644
--- a/Lib/asyncio/__main__.py
+++ b/Lib/asyncio/__main__.py
@@ -3,6 +3,7 @@ import asyncio
import code
import concurrent.futures
import inspect
+import site
import sys
import threading
import types
@@ -109,6 +110,21 @@ if __name__ == '__main__':
except ImportError:
pass
+ interactive_hook = getattr(sys, "__interactivehook__", None)
+
+ if interactive_hook is not None:
+ interactive_hook()
+
+ if interactive_hook is site.register_readline:
+ # Fix the completer function to use the interactive console locals
+ try:
+ import rlcompleter
+ except:
+ pass
+ else:
+ completer = rlcompleter.Completer(console.locals)
+ readline.set_completer(completer.complete)
+
repl_thread = REPLThread()
repl_thread.daemon = True
repl_thread.start()