{"action":"created","issue":{"url":"https://api.github.com/repos/sympy/sympy/issues/11426","repository_url":"https://api.github.com/repos/sympy/sympy","labels_url":"https://api.github.com/repos/sympy/sympy/issues/11426/labels{/name}","comments_url":"https://api.github.com/repos/sympy/sympy/issues/11426/comments","events_url":"https://api.github.com/repos/sympy/sympy/issues/11426/events","html_url":"https://github.com/sympy/sympy/pull/11426","id":167212727,"number":11426,"title":"init_session: improved detection of current IPython session","user":{"login":"elvis-sik","id":11654926,"avatar_url":"https://avatars.githubusercontent.com/u/11654926?v=3","gravatar_id":"","url":"https://api.github.com/users/elvis-sik","html_url":"https://github.com/elvis-sik","followers_url":"https://api.github.com/users/elvis-sik/followers","following_url":"https://api.github.com/users/elvis-sik/following{/other_user}","gists_url":"https://api.github.com/users/elvis-sik/gists{/gist_id}","starred_url":"https://api.github.com/users/elvis-sik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elvis-sik/subscriptions","organizations_url":"https://api.github.com/users/elvis-sik/orgs","repos_url":"https://api.github.com/users/elvis-sik/repos","events_url":"https://api.github.com/users/elvis-sik/events{/privacy}","received_events_url":"https://api.github.com/users/elvis-sik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":31,"created_at":"2016-07-24T02:02:48Z","updated_at":"2016-07-31T05:51:55Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/sympy/sympy/pulls/11426","html_url":"https://github.com/sympy/sympy/pull/11426","diff_url":"https://github.com/sympy/sympy/pull/11426.diff","patch_url":"https://github.com/sympy/sympy/pull/11426.patch"},"body":"Previously, to detect if there was a running IPython session, init_session relied on a function called get_ipython, injected into the global namespace by IPython. However, this function is not in scope during initialization, particularly, it is not in scope during the execution of startup scripts. This had the unfortunate consequence of creating  new mainloop on top of the previous one when init_session was called in a startup script. This commit changes the detection to use IPython.terminal.interactiveshell.TerminalInteractiveShell.initialized, a public-API method that works in this edge case as expected. Hence, it\r\nbecomes possible to use init_session in startup scripts."},"comment":{"url":"https://api.github.com/repos/sympy/sympy/issues/comments/236412546","html_url":"https://github.com/sympy/sympy/pull/11426#issuecomment-236412546","issue_url":"https://api.github.com/repos/sympy/sympy/issues/11426","id":236412546,"user":{"login":"jksuom","id":6929119,"avatar_url":"https://avatars.githubusercontent.com/u/6929119?v=3","gravatar_id":"","url":"https://api.github.com/users/jksuom","html_url":"https://github.com/jksuom","followers_url":"https://api.github.com/users/jksuom/followers","following_url":"https://api.github.com/users/jksuom/following{/other_user}","gists_url":"https://api.github.com/users/jksuom/gists{/gist_id}","starred_url":"https://api.github.com/users/jksuom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jksuom/subscriptions","organizations_url":"https://api.github.com/users/jksuom/orgs","repos_url":"https://api.github.com/users/jksuom/repos","events_url":"https://api.github.com/users/jksuom/events{/privacy}","received_events_url":"https://api.github.com/users/jksuom/received_events","type":"User","site_admin":false},"created_at":"2016-07-31T05:51:55Z","updated_at":"2016-07-31T05:51:55Z","body":"> I tried 0.13.2 and it turns out it doesn't export get_ipython.\r\n\r\nIt seems that such a function is not available in ipython < 1.0, and the initialization has to be done differently.\r\n\r\nIn those versions the import line will raise an ImportError. In that case one should set `ip = None` (with no second try resulting always in a NameError).\r\nThen, if the argument `ipython` of `init_session` is not `None` or `False`,  the control will pass to [this line](https://github.com/sympy/sympy/blob/master/sympy/interactive/session.py#L437) that will do the proper initialization.\r\n\r\nSo, nothing more is needed for those older versions. Setting `ip = None` after `ImportError` and `ipython` not `None` or `False` should suffice."}}
{"actor":{"display_login":"jksuom"}}