Show More
@@ -449,22 +449,28 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
449 | else: |
|
449 | else: | |
450 | default = '' |
|
450 | default = '' | |
451 |
|
451 | |||
452 | with patch_stdout(raw=True): |
|
452 | # In order to make sure that asyncio code written in the | |
453 | # In order to make sure that asyncio code written in the |
|
453 | # interactive shell doesn't interfere with the prompt, we run the | |
454 | # interactive shell doesn't interfere with the prompt, we run the |
|
454 | # prompt in a different event loop. | |
455 | # prompt in a different event loop. |
|
455 | # If we don't do this, people could spawn coroutine with a | |
456 | # If we don't do this, people could spawn coroutine with a |
|
456 | # while/true inside which will freeze the prompt. | |
457 | # while/true inside which will freeze the prompt. |
|
|||
458 |
|
457 | |||
|
458 | try: | |||
459 | old_loop = asyncio.get_event_loop() |
|
459 | old_loop = asyncio.get_event_loop() | |
460 | asyncio.set_event_loop(self.pt_loop) |
|
460 | except RuntimeError: | |
461 | try: |
|
461 | # This happens when the user used `asyncio.run()`. | |
|
462 | old_loop = None | |||
|
463 | ||||
|
464 | asyncio.set_event_loop(self.pt_loop) | |||
|
465 | try: | |||
|
466 | with patch_stdout(raw=True): | |||
462 | text = self.pt_app.prompt( |
|
467 | text = self.pt_app.prompt( | |
463 | default=default, |
|
468 | default=default, | |
464 | **self._extra_prompt_options()) |
|
469 | **self._extra_prompt_options()) | |
465 |
|
|
470 | finally: | |
466 |
|
|
471 | # Restore the original event loop. | |
467 |
|
|
472 | asyncio.set_event_loop(old_loop) | |
|
473 | ||||
468 | return text |
|
474 | return text | |
469 |
|
475 | |||
470 | def enable_win_unicode_console(self): |
|
476 | def enable_win_unicode_console(self): |
General Comments 0
You need to be logged in to leave comments.
Login now