Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Basthon
Basthon Kernel
Commits
4196d003
Commit
4196d003
authored
Dec 01, 2022
by
Romain Casati
Browse files
Python 3: use persistent stream redirection.
parent
85ff3106
Changes
2
Hide whitespace changes
Inline
Side-by-side
packages/kernel-python3/src/basthon/_console.py
View file @
4196d003
...
...
@@ -93,6 +93,17 @@ class InteractiveConsole(_pyodide_console.PyodideConsole):
self
.
execution_count
=
None
kwargs
[
'globals'
]
=
kwargs
.
get
(
'globals'
,
sys
.
modules
[
'__main__'
].
__dict__
)
kwargs
[
'filename'
]
=
kwargs
.
get
(
'filename'
,
"<input>"
)
kwargs
[
'persistent_stream_redirection'
]
=
True
# setup persistent stream redirection
def
stdout_callback
(
text
):
return
self
.
_stdout_callback
(
text
)
kwargs
[
'stdout_callback'
]
=
stdout_callback
def
stderr_callback
(
text
):
return
self
.
_stderr_callback
(
text
)
kwargs
[
'stderr_callback'
]
=
stderr_callback
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
locals
=
self
.
globals
self
.
start
()
...
...
@@ -185,8 +196,8 @@ class InteractiveConsole(_pyodide_console.PyodideConsole):
"""
self
.
locals
[
'__eval_data__'
]
=
data
.
to_py
()
self
.
execution_count
+=
1
self
.
stdout_callback
=
stdout_callback
self
.
stderr_callback
=
stderr_callback
self
.
_
stdout_callback
=
stdout_callback
self
.
_
stderr_callback
=
stderr_callback
self
.
roll_in_history
(
code
)
...
...
packages/kernel-python3/src/basthon/kernel.py
View file @
4196d003
...
...
@@ -24,7 +24,7 @@ importlib.invalidate_caches()
# interpretation system is the Pyodide's interactive console
_console
=
InteractiveConsole
(
persistent_stream_redirection
=
False
)
_console
=
InteractiveConsole
()
def
locals
():
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment