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

Try to capture all filedescriptor output and err #630

Merged
merged 8 commits into from
Apr 20, 2021

Commits on Apr 13, 2021

  1. Try to capture stdout and err going directly to 1/2 filedescriptor.

    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.
    Carreau committed Apr 13, 2021
    Configuration menu
    Copy the full SHA
    ae2f441 View commit details
    Browse the repository at this point in the history
  2. Modify all log handlers to route messages directly screen.

    Bypass the original fd 2 for stderr, and use the new piped one.
    Carreau committed Apr 13, 2021
    Configuration menu
    Copy the full SHA
    f1b8a56 View commit details
    Browse the repository at this point in the history
  3. add tests

    Carreau committed Apr 13, 2021
    Configuration menu
    Copy the full SHA
    799722e View commit details
    Browse the repository at this point in the history
  4. Make sure replaced streams have fileno.

    This is important for example for subprocess that will peak at the
    filedescriptor.
    Carreau committed Apr 13, 2021
    Configuration menu
    Copy the full SHA
    12c8ece View commit details
    Browse the repository at this point in the history
  5. dont capture with pytest

    Carreau committed Apr 13, 2021
    Configuration menu
    Copy the full SHA
    310f0cd View commit details
    Browse the repository at this point in the history
  6. fix test

    Carreau committed Apr 13, 2021
    Configuration menu
    Copy the full SHA
    192fc6c View commit details
    Browse the repository at this point in the history
  7. reformat

    Carreau committed Apr 13, 2021
    Configuration menu
    Copy the full SHA
    79496f0 View commit details
    Browse the repository at this point in the history
  8. flake 8 cleanup

    Carreau committed Apr 13, 2021
    Configuration menu
    Copy the full SHA
    8a160a5 View commit details
    Browse the repository at this point in the history