Skip to content

Output streaming erroneously disabled when hide is in play #637

@bitprophet

Description

@bitprophet

Bewildered this hasn't come up before, but a co-worker was trying to make heavy use of out_stream and found that hide turns off streaming entirely, vs my recollection that eg hide='stdout' or hide=True only turn off the default shoveling to sys.stdout.

However the code is too naive/"pure":

  • The core machinery is Runner._handle_output.
  • It takes a buffer, a bool-for-that-one-stream hide arg, the output stream, etc.
  • The bits making that output stream default to sys.stdout, etc, are higher up - this method doesn't currently know or care how that is determined.
  • If hide indicates this stream should be hidden, the step of self.write_our_output() to the output stream is skipped.
    • As you can guess from the previous bullet point, there's no further logic here - this method does not care whether output was the default-to-your-terminal stream or not.

Obvious solutions:

  • Make 'hide' not applicable to custom stream arguments - this is the absolute most obvious approach and is how I assumed things worked until I double checked. Somehow - either within _handle_output or higher up and add a new kwarg to the former - test whether the user has actually overridden out_stream/err_stream, and ignore hide in that case.
    • Pros: presumably intuitive to most users
    • Cons: leans into 'magic', is arguably backwards incompatible (though I cannot really see somebody RELYING on the current behavior as it basically kills your ability to completely redirect output somewhere else...)
  • Leave as-is, but document that folks should use the watcher functionality instead. In other words, embrace the current "hiding applies to the output streams regardless" behavior and state that you should use a watcher to 'shovel' data elsewhere.
    • Pros: it's a doc fix only so less effort / less breakage
    • Cons: this seems incredibly dumb -- especially given that out_stream/err_stream have always been pitched/intended as "the way you would make stuff go somewhere besides the user's terminal", with watchers coming later and being more of a "stuff you might want to have happen in addition to streaming output to a terminal or log" feature, such as the prompt autoresponse it was built for.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions