Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning with ipython 8.11 (was #35235) #35337

Merged
merged 1 commit into from
Apr 6, 2023

Conversation

tornaria
Copy link
Contributor

📚 Description

ipython 8.11 throws new warnings "UserWarning: Shell was already running a gui event loop for sage; switching to sage." when running some tests.

This is because sage indeed tries to install the same gui event loop for ipython again and again. The fix is checking if the ipython input hook is already set to the sage input hook, in that case we don't install the gui event loop again.

In the test, we run install() twice so we can verify that running it multiple times won't cause a warning anymore.

📝 Checklist

  • I have made sure that the title is self-explanatory and the description concisely explains the PR.
  • I have linked an issue or discussion.
  • I have created tests covering the changes.

⌛ Dependencies

Replaces: #35235

Since gh doesn't allow to change the branch on a PR.

@github-actions
Copy link

Documentation preview for this PR is ready! 🎉
Built with commit: e9c3333

Copy link
Member

@kiwifb kiwifb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already discussed before, and the corrections I suggested did allow the doc to build.

@antonio-rojas
Copy link
Contributor

With ipython 8.12 there seem to be more changes that cause more tests to fail:

**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/attach.py", line 577, in sage.repl.attach.reload_attached_files_if_modified
Failed example:
    shell.run_cell('attach({0})'.format(repr(tmp)))
Expected nothing
Got:
    Installed sage event loop hook.
**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/attach.py", line 588, in sage.repl.attach.reload_attached_files_if_modified
Failed example:
    shell.run_cell('reload_attached_files_if_modified()')
Expected:
    ### reloading attached file tmp_....py modified at ... ###
Got:
    ### reloading attached file tmp_r6sjhvps.py modified at 20:38:38 ###
    Shell is already running a gui event loop for sage. Call with no arguments to disable the current loop.
**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/attach.py", line 593, in sage.repl.attach.reload_attached_files_if_modified
Failed example:
    shell.run_cell('detach({0})'.format(repr(tmp)))
Expected nothing
Got:
    GUI event loop hook disabled.
**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/ipython_extension.py", line 140, in sage.repl.ipython_extension.SageMagics.attach
Failed example:
    shell.run_cell('%attach ' + f.name)
Expected nothing
Got:
    Installed sage event loop hook.
**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/ipython_extension.py", line 150, in sage.repl.ipython_extension.SageMagics.attach
Failed example:
    shell.run_cell('reload_attached_files_if_modified()')
Expected:
    ### reloading attached file ... modified at ... ###
Got:
    ### reloading attached file tmpfm2j96tr.py modified at 20:41:15 ###
    Shell is already running a gui event loop for sage. Call with no arguments to disable the current loop.
**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/ipython_extension.py", line 155, in sage.repl.ipython_extension.SageMagics.attach
Failed example:
    shell.run_cell('detach(%r)' % f.name)
Expected nothing
Got:
    GUI event loop hook disabled.
**********************************************************************

@tornaria
Copy link
Contributor Author

tornaria commented Apr 2, 2023

With ipython 8.12 there seem to be more changes that cause more tests to fail:

**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/attach.py", line 577, in sage.repl.attach.reload_attached_files_if_modified
Failed example:
    shell.run_cell('attach({0})'.format(repr(tmp)))
Expected nothing
Got:
    Installed sage event loop hook.
**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/attach.py", line 588, in sage.repl.attach.reload_attached_files_if_modified
Failed example:
    shell.run_cell('reload_attached_files_if_modified()')
Expected:
    ### reloading attached file tmp_....py modified at ... ###
Got:
    ### reloading attached file tmp_r6sjhvps.py modified at 20:38:38 ###
    Shell is already running a gui event loop for sage. Call with no arguments to disable the current loop.
**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/attach.py", line 593, in sage.repl.attach.reload_attached_files_if_modified
Failed example:
    shell.run_cell('detach({0})'.format(repr(tmp)))
Expected nothing
Got:
    GUI event loop hook disabled.
**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/ipython_extension.py", line 140, in sage.repl.ipython_extension.SageMagics.attach
Failed example:
    shell.run_cell('%attach ' + f.name)
Expected nothing
Got:
    Installed sage event loop hook.
**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/ipython_extension.py", line 150, in sage.repl.ipython_extension.SageMagics.attach
Failed example:
    shell.run_cell('reload_attached_files_if_modified()')
Expected:
    ### reloading attached file ... modified at ... ###
Got:
    ### reloading attached file tmpfm2j96tr.py modified at 20:41:15 ###
    Shell is already running a gui event loop for sage. Call with no arguments to disable the current loop.
**********************************************************************
File "/usr/lib/python3.10/site-packages/sage/repl/ipython_extension.py", line 155, in sage.repl.ipython_extension.SageMagics.attach
Failed example:
    shell.run_cell('detach(%r)' % f.name)
Expected nothing
Got:
    GUI event loop hook disabled.
**********************************************************************

I noticed these and I was wondering what to do about it. I don't see a way to avoid the messages Installed sage event loop hook. and GUI event loop hook disabled. since they are hardcoded in ipython with no way to silence them.

OTOH, the message Shell is already running a gui event loop for sage. Call with no arguments to disable the current loop. is not shown at all when this PR is applied, since we no longer reinstall the event loop.

Note that Volker is already merging this PR in his tree, so I'll keep it as is and open a new PR for ipython 8.12.

@tornaria tornaria mentioned this pull request Apr 2, 2023
4 tasks
@vbraun vbraun merged commit 47abd1b into sagemath:develop Apr 6, 2023
@mkoeppe mkoeppe added this to the sage-10.0 milestone Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants