Check if we're running in an interactive shell. Returns ------- bool True if running under python/ipython interactive shell.
()
| 53 | |
| 54 | |
| 55 | def in_interactive_session() -> bool: |
| 56 | """ |
| 57 | Check if we're running in an interactive shell. |
| 58 | |
| 59 | Returns |
| 60 | ------- |
| 61 | bool |
| 62 | True if running under python/ipython interactive shell. |
| 63 | """ |
| 64 | from pandas import get_option |
| 65 | |
| 66 | def check_main() -> bool: |
| 67 | try: |
| 68 | import __main__ as main |
| 69 | except ModuleNotFoundError: |
| 70 | return get_option("mode.sim_interactive") |
| 71 | return not hasattr(main, "__file__") or get_option("mode.sim_interactive") |
| 72 | |
| 73 | try: |
| 74 | # error: Name '__IPYTHON__' is not defined |
| 75 | return __IPYTHON__ or check_main() # type: ignore[name-defined] |
| 76 | except NameError: |
| 77 | return check_main() |
| 78 | |
| 79 | |
| 80 | def in_ipython_frontend() -> bool: |
no test coverage detected