Giter VIP home page Giter VIP logo

Comments (5)

joeyh avatar joeyh commented on July 19, 2024

I am not a python developer, but I read https://stackoverflow.com/questions/107705/disable-output-buffering and found this patch works:


diff --git a/dish_grpc_text.py b/dish_grpc_text.py
index 29b844e..52821e9 100644
--- a/dish_grpc_text.py
+++ b/dish_grpc_text.py
@@ -110,7 +110,7 @@ def parse_args():
 def open_out_file(opts, mode):
     if opts.out_file == "-":
         # open new file, so it can be closed later without affecting sys.stdout
-        return os.fdopen(sys.stdout.fileno(), "w", closefd=False)
+        return os.fdopen(sys.stdout.fileno(), "w", 1, closefd=False)
     return open(opts.out_file, mode, buffering=1)

from starlink-grpc-tools.

sparky8512 avatar sparky8512 commented on July 19, 2024

By default, Python will buffer stdout unless it is a TTY, so redirecting into a pipe (or a file, for that matter) will cause it to buffer.

I thought about forcing it to line buffer, at least in the text output script, but that seems to me that it would be taking away flexibility in case someone actually wants it to buffer. I also thought about making it a command line option, but there is already a command line option to the python executable that will prevent it from buffering: the -u option. For example:

python3 -u dish_grpc_text.py status -t 1|cat

should do what you want.

I could probably be convinced that it would be better to just always line buffer in that script. In my own usage, I use that -u interpreter option because I redirect to a file and I try to minimize data loss when the power goes out, and I can't really think of a use case where someone needs it to be block buffered.

from starlink-grpc-tools.

joeyh avatar joeyh commented on July 19, 2024

-u does not work for me. (Python 3.10.4)

Note that this also breaks basic use with grep if you just want to watch a single value for changes while looping..

from starlink-grpc-tools.

joeyh avatar joeyh commented on July 19, 2024

As far as I can see, the only benefit to block buffering is fewer syscalls. But why would you be worried about a few syscalls when running this in a loop?

from starlink-grpc-tools.

sparky8512 avatar sparky8512 commented on July 19, 2024

-u does not work for me. (Python 3.10.4)

Oh. Yeah. I probably broke this when I changed it to reopen the output file in order to support specifying a file for output. Even if that weren't the case, I think I agree with you that there really isn't any benefit to block buffering for this script, given the data rate.

I will change it to always line buffer the output.

from starlink-grpc-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.