-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Try to capture all filedescriptor output and err #630
Conversation
This looks great! One more edge case that may be something to cover here or in a separate PR:
|
I've added a I'd like to at least get a thumb up from @SylvainCorlay or someone of the xeus-python team, I'm not sure how they manipulate stderr/out and if that affects them. Test will be incomplete as pytest seem to setup its own redirection to capture stderr/out which messes up our redirection. |
This try to fix a long standing issue that stdout and stderr going directly to the filedescriptor are not shown in notebooks. This is annoying when using wrappers around c-libraries, or calling system commands as those will not be seen from within notebook. Here we redirect and split the filedescriptor and watch those in threads and redirect both to the original FD (terminal), and ZMQ (notebook). Thus output sent to fd 1 & 2 will be shown BOTH in terminal that launched the notebook server and in notebook themselves. One of the concern is that now logs and errors internal to ipykernel may appear in the notebook themselves, so may confuse user; though these should be limited to error and debug; and we can workaround this by setting the log handler to not be stdout/err. This still seem like a big hack to me, and I don't like thread. I did not manage to make reading the FD non-blocking; so this cannot be put in the io-thread – at least I'm not sure how. So adds 2 extra threads to the kernel. This might need to be turn off by default for now until further testing. Locally this seem to work with things like: - os.system("echo HELLO WORLD") - c-extensions writing directly to fd 1 and 2 (when properly flushed). I have no clue how filedescriptor work on windows, so this only change behavior on linux and mac.
Bypass the original fd 2 for stderr, and use the new piped one.
This is important for example for subprocess that will peak at the filedescriptor.
Thank you for pinging me @Carreau. @martinRenou was looking into something along the same lines, just when you posted your Pull Request. Let's look more into this. |
Let's merge to see if we get issues on master; feel free to revert and merge the revert if you encounter andy issues. |
That's how you do it :) |
This try to fix a long standing issue that stdout and stderr going
directly to the filedescriptor are not shown in notebooks.
This is annoying when using wrappers around c-libraries, or calling
system commands as those will not be seen from within notebook.
Here we redirect and split the filedescriptor and watch those in threads
and redirect both to the original FD (terminal), and ZMQ (notebook).
Thus output sent to fd 1 & 2 will be shown BOTH in terminal that
launched the notebook server and in notebook themselves.
One of the concern is that now logs and errors internal to ipykernel may
appear in the notebook themselves, so may confuse user; though these
should be limited to error and debug; and we can workaround this by
setting the log handler to not be stdout/err.
This still seem like a big hack to me, and I don't like thread.
I did not manage to make reading the FD non-blocking; so this cannot be
put in the io-thread – at least I'm not sure how. So adds 2 extra
threads to the kernel.
This might need to be turn off by default for now until further testing.
Locally this seem to work with things like:
I have no clue how filedescriptor work on windows, so this only change
behavior on linux and mac.