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

Force flush for rcutils logging #70

Closed
dhood opened this issue Nov 15, 2017 · 4 comments
Closed

Force flush for rcutils logging #70

dhood opened this issue Nov 15, 2017 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@dhood
Copy link
Member

dhood commented Nov 15, 2017

We have code that forces flushing of stdout in some places, particularly so that launch file prints sync. This includes python scripts that call sys.stdout.flush(). After switching to use rcutils logging (via python wrappers), sys.stdout.flush() will do nothing for python scripts, and they will not have a way to force flush.

Consider an environment variable similar to ros/ros_comm#1012.

@dhood
Copy link
Member Author

dhood commented Nov 15, 2017

Python scripts can use PYTHONUNBUFFERED for now, so this is less of a priority. This will still be useful for the C/C++ code to have forced flushing configured externally as opposed to hard-coded, and to have control over all languages with one configuration.

@dhood dhood added help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Feb 22, 2018
@iankuan
Copy link
Contributor

iankuan commented Mar 1, 2018

Hello @dhood. I don't see there will be an elegant way rather than ugly hack for all languages. Maybe we can do something in shell command. However, buffering mechanism is specified by POSIX. Have anyone got any idea about that? I see the label here, and wanna try it out.

@dhood
Copy link
Member Author

dhood commented Mar 3, 2018

@yenwu thanks for your interest!

The objective is to remove the need for hard-coding anything to force flushing in ROS applications themselves (as you noted it changes for each language). This can be accomplished with an environment variable instead. That way, the decision to use or not use unbuffered output can be made when the process is run. The good thing is that rclpy and rclcpp both use rcutils for logging, and so the environment variable will affect both, without needing a different approach for all languages.

ros/ros_comm#1012 shows how this has been accomplished in ROS 1. It would be good to copy that PR into rcutils, so that we call fflush after console output is printed. Note that instead of get_environment_variable you can use rcutils_get_env like we do for other logging initialisation.

How does that sound?

@sloretz sloretz mentioned this issue Mar 16, 2018
@dirk-thomas
Copy link
Member

Addressed by #98.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants