8000 Switch from 'embedding' to 'starting' IPython · reddit/baseplate.py@85c5c05 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 85c5c05

Browse files
committed
Switch from 'embedding' to 'starting' IPython
Embedding IPython results in issues where import statements and other globals changes in the shell environment don't work as expected.[1] As an example, the following commands result in a NameError: In [1]: import time In [2]: def foo(): ...: print(time.time()) ...: In [3]: foo() --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-3-c19b6d9633cf> in <module> ----> 1 foo() <ipython-input-2-a038e7f91c93> in foo() 1 def foo(): ----> 2 print(time.time()) 3 NameError: name 'time' is not defined By switching to use "start_ipython()" instead, we get an environment more similar to what we get by running `ipython` directly. [1] ipython/ipython#62
1 parent 14eaf99 commit 85c5c05

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

baseplate/server/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,10 @@ def load_and_run_shell() -> None:
374374

375375
try:
376376
# try to use IPython if possible
377-
from IPython.terminal.embed import InteractiveShellEmbed
378-
from IPython.core.interactiveshell import DummyMod
377+
from IPython import start_ipython
379378

380-
shell = InteractiveShellEmbed(banner2=banner)
381-
shell(local_ns=env, module=DummyMod())
379+
start_ipython(argv=[], user_ns=env)
380+
raise SystemExit
382381
except ImportError:
383382
import code
384383

0 commit comments

Comments
 (0)
0