Page MenuHomeDevCentral

Flush stdout after a notification has been printed
ClosedPublic

Authored by dereckson on Feb 21 2016, 07:01.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 12, 18:08
Unknown Object (File)
Sun, Nov 10, 02:48
Unknown Object (File)
Sat, Nov 9, 15:30
Unknown Object (File)
Fri, Nov 8, 20:27
Unknown Object (File)
Fri, Nov 8, 20:03
Unknown Object (File)
Thu, Nov 7, 23:11
Unknown Object (File)
Thu, Nov 7, 22:12
Unknown Object (File)
Mon, Oct 28, 13:09
Subscribers

Details

Summary

Fixes T754.

Test Plan

Fire a notification and see if it's correctly printed.

./notifications | tee -a /home/dereckson/public_html/notifications.log
[06:56:32] <Nasqueron/nasqueron> dereckson created T754: ./notifications > file.log or | tee file.log doesn't immediately flush messages.

Diff Detail

Repository
rNOTIFCLI Notifications center CLI client
Lint
Lint Passed
Unit
No Test Coverage
Branch
fix/buffer
Build Status
Buildable 378
Build 455: arc lint + arc unit

Event Timeline

dereckson retitled this revision from to Flush stdout after a notification has been printed.
dereckson updated this object.
dereckson edited the test plan for this revision. (Show Details)
dereckson added a reviewer: dereckson.
dereckson added a subscriber: rama.
dereckson added a subscriber: Sandlayth.

@rama @Kaliiixx You'll love this one: a queer behavior I spotted in Python 3:

./script works perfectly: every time something is printed, it's shown on stdout

But ./script > file.log won't write immediately, it will buffer the output.

No more output? You ctrl + C the script to end it? Bye the output … (to mitigate that: a TERM signal, the one you got with kill <pid>, will nicely quits the Python script after a flush)

Now imagine this script. It's intended to follow notifications as a LIVE stream. But if you want a log and do ./script | tee file.log, you lost the live feature.

So we need to explicitly flush the stdout, to be able to use that with tee the way any user would expect it to work: sys.stdout.flush().

See also https://www.turnkeylinux.org/blog/unix-buffering

dereckson edited edge metadata.

Tested on Ysul, works perfectly.

This revision is now accepted and ready to land.Feb 21 2016, 07:08
This revision was automatically updated to reflect the committed changes.