MCPcopy Index your code
hub / github.com/RustPython/RustPython / AsyncIOInteractiveConsole

Class AsyncIOInteractiveConsole

Lib/asyncio/__main__.py:21–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19
20
21class AsyncIOInteractiveConsole(InteractiveColoredConsole):
22
23 def __init__(self, locals, loop):
24 super().__init__(locals, filename="<stdin>")
25 self.compile.compiler.flags |= ast.PyCF_ALLOW_TOP_LEVEL_AWAIT
26
27 self.loop = loop
28 self.context = contextvars.copy_context()
29
30 def runcode(self, code):
31 global return_code
32 future = concurrent.futures.Future()
33
34 def callback():
35 global return_code
36 global repl_future
37 global keyboard_interrupted
38
39 repl_future = None
40 keyboard_interrupted = False
41
42 func = types.FunctionType(code, self.locals)
43 try:
44 coro = func()
45 except SystemExit as se:
46 return_code = se.code
47 self.loop.stop()
48 return
49 except KeyboardInterrupt as ex:
50 keyboard_interrupted = True
51 future.set_exception(ex)
52 return
53 except BaseException as ex:
54 future.set_exception(ex)
55 return
56
57 if not inspect.iscoroutine(coro):
58 future.set_result(coro)
59 return
60
61 try:
62 repl_future = self.loop.create_task(coro, context=self.context)
63 futures._chain_future(repl_future, future)
64 except BaseException as exc:
65 future.set_exception(exc)
66
67 self.loop.call_soon_threadsafe(callback, context=self.context)
68
69 try:
70 return future.result()
71 except SystemExit as se:
72 return_code = se.code
73 self.loop.stop()
74 return
75 except BaseException:
76 if keyboard_interrupted:
77 if not CAN_USE_PYREPL:
78 self.write("\nKeyboardInterrupt\n")

Callers 1

__main__.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected