question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable output buffering by default

See original GitHub issue

Feature 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
clalancettecommented, Feb 3, 2021

I’m OK with changing the default behavior of the CLI to be unbuffered by default. I just want to make sure that:

  1. All of the CLI tools are consistent, and
  2. That there is a way to go back to buffered mode if the user wants
0reactions
ivanpaunocommented, Aug 10, 2021

What if we instead set PYTHONUNBUFFERED=1 at startup by default, and then let the user disable it using the same mechanism if they want?

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable output buffering - python - Stack Overflow
Yes, it is enabled by default. You can disable it by using the -u option on the command line when calling python.
Read more >
What Is Python Output Buffering and How to Disable It? - Finxter
Another approach to disable the output buffering in python is to open up the stdout in write mode with buffer size set to...
Read more >
How to enable and disable the PHP output_buffering directive
To enable output buffering, use a text editor to modify the output_buffering directive in the php.ini file as follows: output_buffering = on.
Read more >
How do I disable Joomla output buffering? - website builder
1. Navigate to the Site Administration section of your Joomla website. · 2. Select the Options tab. · 3. Under the Output heading,...
Read more >
How to Check if Python's Output Buffering Is Enabled
To disable output buffering, you can run Python with the -u option or by setting the PYTHONUNBUFFERED environment variable. However, there's no ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found