Show More
@@ -35,6 +35,7 b' import hashlib' | |||
|
35 | 35 | import linecache |
|
36 | 36 | import operator |
|
37 | 37 | import time |
|
38 | from contextlib import contextmanager | |
|
38 | 39 | |
|
39 | 40 | #----------------------------------------------------------------------------- |
|
40 | 41 | # Constants |
@@ -134,6 +135,17 b' class CachingCompiler(codeop.Compile):' | |||
|
134 | 135 | linecache._ipython_cache[name] = entry |
|
135 | 136 | return name |
|
136 | 137 | |
|
138 | @contextmanager | |
|
139 | def extra_flags(self, flags): | |
|
140 | old_flags = self.flags | |
|
141 | self.flags = self.flags | flags | |
|
142 | print('flags', old_flags ,'->', self.flags) | |
|
143 | try: | |
|
144 | yield | |
|
145 | finally: | |
|
146 | self.flags = old_flags | |
|
147 | ||
|
148 | ||
|
137 | 149 | def check_linecache_ipython(*args): |
|
138 | 150 | """Call linecache.checkcache() safely protecting our cached values. |
|
139 | 151 | """ |
@@ -210,6 +210,8 b' def _ast_asyncify(cell:str, wrapper_name:str) -> ast.Module:' | |||
|
210 | 210 | """ |
|
211 | 211 | |
|
212 | 212 | from ast import Expr, Await, Return |
|
213 | if sys.version_info >= (3,8): | |
|
214 | return ast.parse(cell) | |
|
213 | 215 | tree = ast.parse(_asyncify(cell)) |
|
214 | 216 | |
|
215 | 217 | function_def = tree.body[0] |
@@ -3194,11 +3196,12 b' class InteractiveShell(SingletonConfigurable):' | |||
|
3194 | 3196 | elif interactivity == 'all': |
|
3195 | 3197 | to_run_exec, to_run_interactive = [], nodelist |
|
3196 | 3198 | elif interactivity == 'async': |
|
3199 | to_run_exec, to_run_interactive = [], nodelist | |
|
3197 | 3200 | _async = True |
|
3198 | 3201 | else: |
|
3199 | 3202 | raise ValueError("Interactivity was %r" % interactivity) |
|
3200 | 3203 | try: |
|
3201 | if _async: | |
|
3204 | if _async and sys.version_info < (3,8): | |
|
3202 | 3205 | # If interactivity is async the semantics of run_code are |
|
3203 | 3206 | # completely different Skip usual machinery. |
|
3204 | 3207 | mod = Module(nodelist, []) |
@@ -3215,9 +3218,11 b' class InteractiveShell(SingletonConfigurable):' | |||
|
3215 | 3218 | return True |
|
3216 | 3219 | |
|
3217 | 3220 | for i, node in enumerate(to_run_interactive): |
|
3221 | print('B: interactive, async=', _async, nodelist) | |
|
3218 | 3222 | mod = ast.Interactive([node]) |
|
3219 | code = compiler(mod, cell_name, "single") | |
|
3220 | if (yield from self.run_code(code, result)): | |
|
3223 | with compiler.extra_flags(0x2000 if _async else 0x0): | |
|
3224 | code = compiler(mod, cell_name, "single") | |
|
3225 | if (yield from self.run_code(code, result, async_=_async)): | |
|
3221 | 3226 | return True |
|
3222 | 3227 | |
|
3223 | 3228 | # Flush softspace |
@@ -3288,10 +3293,12 b' class InteractiveShell(SingletonConfigurable):' | |||
|
3288 | 3293 | try: |
|
3289 | 3294 | try: |
|
3290 | 3295 | self.hooks.pre_run_code_hook() |
|
3291 | if async_: | |
|
3296 | if async_ and sys.version_info < (3,8): | |
|
3292 | 3297 | last_expr = (yield from self._async_exec(code_obj, self.user_ns)) |
|
3293 | 3298 | code = compile('last_expr', 'fake', "single") |
|
3294 | 3299 | exec(code, {'last_expr': last_expr}) |
|
3300 | elif async_ : | |
|
3301 | res = yield from eval(code_obj, self.user_ns) | |
|
3295 | 3302 | else: |
|
3296 | 3303 | exec(code_obj, self.user_global_ns, self.user_ns) |
|
3297 | 3304 | finally: |
General Comments 0
You need to be logged in to leave comments.
Login now