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

PR: Fix handling of kernel stderr, and capture stdout and segfaults too (IPython console) #14025

Merged
merged 13 commits into from
Nov 17, 2021

Conversation

impact27
Copy link
Contributor

@impact27 impact27 commented Oct 20, 2020

Description of Changes

Sometines, c libraries will print something to the actual stdout and stderr, instead of using the ipykernel ones. This saves these messages to a file and displays them in the console.

  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)
  • Included a screenshot or animation (if affecting the UI, see Licecap)

Issue(s) Resolved

Fixes #13991
Fixes #9759
Fixes #1922

Depends on #16766
Depends on jupyter/qtconsole#450

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct:

@pep8speaks
Copy link

pep8speaks commented Oct 20, 2020

Hello @impact27! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-11-17 18:55:26 UTC

@ccordoba12
Copy link
Member

@impact27, it seems you haven't pushed your changes to spyder-kernels to a corresponding PR in that repo.

@impact27
Copy link
Contributor Author

@impact27
Copy link
Contributor Author

impact27 commented Nov 9, 2020

Fixes #1922 as well

@impact27
Copy link
Contributor Author

Should I leave this on 4.x or move it to 5.x?

@ccordoba12 ccordoba12 changed the base branch from 4.x to 5.x October 10, 2021 17:03
@ccordoba12
Copy link
Member

This needs to wait until @dalthviz finishes the migration of the IPython console to the new API in PR #16324.

@ccordoba12
Copy link
Member

@impact27, could you fix the merge conflicts and try to finish this PR as soon as you can?

Sorry for the rush, but I need the fixes you're doing here to the console shutdown logic to finish PR #16409. That's because our tests are failing with a segfault there, which seems related to the problem @rear1019 was trying to solve on PR #16585.

@ccordoba12
Copy link
Member

ccordoba12 commented Nov 4, 2021

@impact27, could you fix the merge conflicts and try to finish this PR as soon as you can?

Let me know if you need help with that, so you can keep working on this.

@impact27 impact27 force-pushed the std_files branch 2 times, most recently from 737d9b5 to a0e9b6a Compare November 5, 2021 15:57
@ccordoba12 ccordoba12 modified the milestones: 4.x, v5.2.0 Nov 5, 2021
@impact27
Copy link
Contributor Author

impact27 commented Nov 6, 2021

@ccordoba12 Depends on jupyter/qtconsole#505

@impact27
Copy link
Contributor Author

impact27 commented Nov 6, 2021

@ccordoba12 The tests might pass without jupyter/qtconsole#505. When it is merged the last commit can be removed and the tests will be more stable.


def __del__(self):
"""Close threads to avoid segfault"""
"""Close threads to avoid segfault."""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is likely an issue as well, but not covered in this PR. Don't close spyder while restarting a kernel?

Quentin Peter and others added 3 commits November 10, 2021 13:36
…der-ide/spyder-kernels.git external-deps/spyder-kernels

subrepo:
  subdir:   "external-deps/spyder-kernels"
  merged:   "efe0a3f22"
upstream:
  origin:   "https://github.com/spyder-ide/spyder-kernels.git"
  branch:   "2.x"
  commit:   "efe0a3f22"
git-subrepo:
  version:  "0.4.1"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "a04d8c2"
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Thanks @impact27 for this improvement! It looks really good to me, except for the minor comments and suggestions I left below.

Also, I have a question for you: does this new functionality not replace what Wurlitzer does? If that's the case, should we not remove Wurlitzer from the kernel dependencies?

spyder/app/tests/test_mainwindow.py Outdated Show resolved Hide resolved
spyder/app/tests/test_mainwindow.py Outdated Show resolved Hide resolved
spyder/app/tests/test_mainwindow.py Outdated Show resolved Hide resolved
spyder/plugins/ipythonconsole/widgets/client.py Outdated Show resolved Hide resolved
spyder/plugins/ipythonconsole/widgets/client.py Outdated Show resolved Hide resolved
spyder/plugins/ipythonconsole/widgets/client.py Outdated Show resolved Hide resolved
spyder/plugins/ipythonconsole/widgets/client.py Outdated Show resolved Hide resolved
@@ -478,7 +558,10 @@ def stop_button_click_handler(self):

def show_kernel_error(self, error):
"""Show kernel initialization errors in infowidget."""
InstallerIPythonKernelError(error)
self.error_text = error
if "issue1666807" not in error:
Copy link
Member

Choose a reason for hiding this comment

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

This looks really ugly and it could lead to problems when building the installer for publishing it.

@mrclary, what do you think about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@impact27, what is the significance of "issue1666807"? InstallerIPythonKernelError is perfectly safe to execute under any circumstance, so does not require flow control. InstallerIPythonKernelError will not do anything unless the installer test is running, i.e. the system environment variable INSTALLER_TEST=1; this only occurs on the GitHub server when explicitly testing the macOS application build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When building the installer, the work in this PR reveals that an error is printer relative to https://bugs.python.org/issue1666807. Basically python complains that some paths are relative and not absolute. I guess this is made to have a portable installer. I don't think the code here creates this error but rather reveals it. I will remove this but I think this will make the installer tests fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Error in the Create macOS App Bundle and DMG / macOS App Bundle (Lite) test:

  This version of python seems to be incorrectly compiled
  (internal generated filenames are not absolute).
  This may make the debugger miss breakpoints.
  Related bug: http://bugs.python.org/issue1666807

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I've seen this happen recently. It is not related to anything in this PR and this PR did not uncover it. As far as this PR is concerned, that is good news. I was not aware, however, that it was causing the installer test to fail. AFAIK, this may not present an actual issue when using Spyder, but nevertheless needs to be addressed. I'll look into it right away.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, quick clarification. This warning printed in the IPython console began showing up recently, but did not cause the installer to fail. This PR did begin causing the installer to fail; I assume that it was not captured before this PR. I don't know how malicious this warning is, but I'll try to find the root cause.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could add back the if "issue1666807" not in error: so the tests pass and add an issue to the issue tracker so this can be handled separately?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, I think that is our only option right now. This issue has me stumped. I think we should reopen #16828 rather than creating a new issue.

@ccordoba12 ccordoba12 changed the title PR: Fix stdout and stderr handling PR: Fix handling of kernel stderr, and capture stdout and segfaults too (IPython console) Nov 14, 2021
@impact27
Copy link
Contributor Author

Also, I have a question for you: does this new functionality not replace what Wurlitzer does? If that's the case, should we not remove Wurlitzer from the kernel dependencies?

This approach wouldn't work for kernels not started by spyder, so Wurlitzer might still be useful.

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

@impact27, I left a tiny suggestion for you, then it should be ready.

Also, please rebase on top of 5.x to get the fix to our tests I made in PR #16845.

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

This is a terrific improvement! Thanks a lot @impact27 for your work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'cerr' output multiplied with multiple clicks of 'Run'.
4 participants