Allow to change the status of the autoawait option. This allow you to set a specific asynchronous code runner. If no value is passed, print the currently used asynchronous integration and whether it is activated. It can take a number of value evaluated in
(self, parameter_s)
| 687 | |
| 688 | @line_magic |
| 689 | def autoawait(self, parameter_s): |
| 690 | """ |
| 691 | Allow to change the status of the autoawait option. |
| 692 | |
| 693 | This allow you to set a specific asynchronous code runner. |
| 694 | |
| 695 | If no value is passed, print the currently used asynchronous integration |
| 696 | and whether it is activated. |
| 697 | |
| 698 | It can take a number of value evaluated in the following order: |
| 699 | |
| 700 | - False/false/off deactivate autoawait integration |
| 701 | - True/true/on activate autoawait integration using configured default |
| 702 | loop |
| 703 | - asyncio/curio/trio activate autoawait integration and use integration |
| 704 | with said library. |
| 705 | |
| 706 | - `sync` turn on the pseudo-sync integration (mostly used for |
| 707 | `IPython.embed()` which does not run IPython with a real eventloop and |
| 708 | deactivate running asynchronous code. Turning on Asynchronous code with |
| 709 | the pseudo sync loop is undefined behavior and may lead IPython to crash. |
| 710 | |
| 711 | If the passed parameter does not match any of the above and is a python |
| 712 | identifier, get said object from user namespace and set it as the |
| 713 | runner, and activate autoawait. |
| 714 | |
| 715 | If the object is a fully qualified object name, attempt to import it and |
| 716 | set it as the runner, and activate autoawait. |
| 717 | |
| 718 | The exact behavior of autoawait is experimental and subject to change |
| 719 | across version of IPython and Python. |
| 720 | """ |
| 721 | |
| 722 | param = parameter_s.strip() |
| 723 | d = {True: "on", False: "off"} |
| 724 | |
| 725 | if not param: |
| 726 | print("IPython autoawait is `{}`, and set to use `{}`".format( |
| 727 | d[self.shell.autoawait], |
| 728 | self.shell.loop_runner |
| 729 | )) |
| 730 | return None |
| 731 | |
| 732 | if param.lower() in ('false', 'off'): |
| 733 | self.shell.autoawait = False |
| 734 | return None |
| 735 | if param.lower() in ('true', 'on'): |
| 736 | self.shell.autoawait = True |
| 737 | return None |
| 738 | |
| 739 | if param in self.shell.loop_runner_map: |
| 740 | self.shell.loop_runner, self.shell.autoawait = self.shell.loop_runner_map[param] |
| 741 | return None |
| 742 | |
| 743 | if param in self.shell.user_ns : |
| 744 | self.shell.loop_runner = self.shell.user_ns[param] |
| 745 | self.shell.autoawait = True |
| 746 | return None |
nothing calls this directly
no test coverage detected