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)
| 598 | |
| 599 | @line_magic |
| 600 | def autoawait(self, parameter_s): |
| 601 | """ |
| 602 | Allow to change the status of the autoawait option. |
| 603 | |
| 604 | This allow you to set a specific asynchronous code runner. |
| 605 | |
| 606 | If no value is passed, print the currently used asynchronous integration |
| 607 | and whether it is activated. |
| 608 | |
| 609 | It can take a number of value evaluated in the following order: |
| 610 | |
| 611 | - False/false/off deactivate autoawait integration |
| 612 | - True/true/on activate autoawait integration using configured default |
| 613 | loop |
| 614 | - asyncio/curio/trio activate autoawait integration and use integration |
| 615 | with said library. |
| 616 | |
| 617 | - `sync` turn on the pseudo-sync integration (mostly used for |
| 618 | `IPython.embed()` which does not run IPython with a real eventloop and |
| 619 | deactivate running asynchronous code. Turning on Asynchronous code with |
| 620 | the pseudo sync loop is undefined behavior and may lead IPython to crash. |
| 621 | |
| 622 | If the passed parameter does not match any of the above and is a python |
| 623 | identifier, get said object from user namespace and set it as the |
| 624 | runner, and activate autoawait. |
| 625 | |
| 626 | If the object is a fully qualified object name, attempt to import it and |
| 627 | set it as the runner, and activate autoawait. |
| 628 | |
| 629 | |
| 630 | The exact behavior of autoawait is experimental and subject to change |
| 631 | across version of IPython and Python. |
| 632 | """ |
| 633 | |
| 634 | param = parameter_s.strip() |
| 635 | d = {True: "on", False: "off"} |
| 636 | |
| 637 | if not param: |
| 638 | print("IPython autoawait is `{}`, and set to use `{}`".format( |
| 639 | d[self.shell.autoawait], |
| 640 | self.shell.loop_runner |
| 641 | )) |
| 642 | return None |
| 643 | |
| 644 | if param.lower() in ('false', 'off'): |
| 645 | self.shell.autoawait = False |
| 646 | return None |
| 647 | if param.lower() in ('true', 'on'): |
| 648 | self.shell.autoawait = True |
| 649 | return None |
| 650 | |
| 651 | if param in self.shell.loop_runner_map: |
| 652 | self.shell.loop_runner, self.shell.autoawait = self.shell.loop_runner_map[param] |
| 653 | return None |
| 654 | |
| 655 | if param in self.shell.user_ns : |
| 656 | self.shell.loop_runner = self.shell.user_ns[param] |
| 657 | self.shell.autoawait = True |
nothing calls this directly
no test coverage detected