Disable output buffering by default
See original GitHub issueFeature request
Feature description
The current default of Python buffering output can lead to undesirable behavior when working with ros2cli
tools. For example,
ros2 echo /chatter | grep "Hello"
won’t output messages right away unless I disable buffering with PYTHONUNBUFFERED=1
.
I’ve created this ticket to discuss if we should default to disabling output buffering. Though we’ve had this discussion related to other features/tools in ROS 2, I couldn’t find much about the CLI tools (just this: https://github.com/ros2/ros2cli/pull/588).
Implementation considerations
Cons:
Disabling output buffering can lead to performance issues. But, I’d argue that it would be acceptable presuming these tools are primarily used for debugging, and they are not very performant as-is.
Pros:
Users won’t get confused when they rely on output of ros2cli
tools not immediately being fed into another process.
E.g. tests won’t have to explicitly set PYTHONUNBUFFERED.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (4 by maintainers)
Top GitHub Comments
I’m OK with changing the default behavior of the CLI to be unbuffered by default. I just want to make sure that:
I don’t think you can do that exactly, IIUC
PYTHOUNBUFFERED
is an environment variable that python checks only at startup. There’re ways to programatically make stdout unbuffered in python, but all the ones that I found are a bit hacky.I will take a look if I can find an easy way to do it, or apply one of the hacky ways to do it. I will probably enable line buffering instead of unbuffered output, which is reasonable for this use case.