@@ -130,21 +130,19 @@ export class BaseEvalElement extends HTMLElement {
130
130
try {
131
131
source = this . source ? await this . getSourceFromFile ( this . source )
132
132
: this . getSourceFromElement ( ) ;
133
+ const is_async = source . includes ( 'asyncio' )
133
134
134
135
await this . _register_esm ( pyodide ) ;
135
-
136
- if ( source . includes ( 'asyncio' ) ) {
136
+ if ( is_async ) {
137
137
await pyodide . runPythonAsync (
138
138
`output_manager.change(out="${ this . outputElement . id } ", err="${ this . errorElement . id } ", append=${ this . appendOutput ? 'True' : 'False' } )` ,
139
139
) ;
140
140
output = await pyodide . runPythonAsync ( source ) ;
141
- await pyodide . runPythonAsync ( `output_manager.revert()` ) ;
142
141
} else {
143
142
output = pyodide . runPython (
144
143
`output_manager.change(out="${ this . outputElement . id } ", err="${this . errorElement . id } ", append=${ this . appendOutput ? 'True' : 'False' } )`,
145
144
) ;
146
145
output = pyodide . runPython ( source ) ;
147
- pyodide . runPython ( `output_manager.revert()` ) ;
148
146
}
149
147
150
148
if ( output !== undefined ) {
@@ -158,6 +156,12 @@ export class BaseEvalElement extends HTMLElement {
158
156
this . outputElement . style . display = 'block' ;
159
157
}
160
158
159
+ if ( is_async ) {
160
+ await pyodide . runPythonAsync ( `output_manager.revert()` ) ;
161
+ } else {
162
+ await pyodide . runPython ( `output_manager.revert()` ) ;
163
+ }
164
+
161
165
// check if this REPL contains errors, delete them and remove error classes
162
166
const errorElements = document . querySelectorAll ( `div[id^='${ this . errorElement . id } '][error]` ) ;
163
167
if ( errorElements . length > 0 ) {
0 commit comments