Opened 11 years ago

Closed 11 years ago

#9369 closed enhancement (fixed)

make verbose command flush its output

Reported by: was Owned by: jason
Priority: minor Milestone: sage-4.6.2
Component: misc Keywords:
Cc: Merged in: sage-4.6.2.alpha1
Authors: William Stein Reviewers: Robert Miller
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges


Attachments (1)

trac_9369.patch (580 bytes) - added by was 11 years ago.

Download all attachments as: .zip

Change History (7)

Changed 11 years ago by was

comment:1 Changed 11 years ago by was

  • Status changed from new to needs_review

The point of this is that if you do

sage foo.sage > output.out
tail -f output.out

and use verbose(...) in foo.sage, you'll see nothing for a while, which sucks.

comment:2 Changed 11 years ago by rlm

This might or might not be slightly off topic. Without verbose, it doesn't seem to be flushing at all. I tried the following in a file called test.sage with ./sage test.sage > ~/foo.txt and tail -f ~/foo.txt only showed the output once I interrupted the loop.

for E in cremona_optimal_curves(range(10000)):
    print E.label(), E.sha().an()

I remember doing something like this a long time ago and it working. Wassupwiddat?

comment:3 Changed 11 years ago by rlm

Also, if I don't stream the output to a file, it does print in real time. Am I missing a linux-ism here?

comment:4 Changed 11 years ago by jsrn

This sort of behaviour is standard in most programming languages for efficiency: whenever the OS is asked to print to a file (and in some cases, also if it is to a terminal), it collects output until some buffer is filled, and this entire buffer is then output in one go. If flushing is needed (e.g. for when output is only produced rarely between heavy computations), it should be explicitly stated.

I am not completely sure if the above usage corresponds well to the intended workflow of the verbose function, but this concern should at least be considered before adding the mandatory flush statement. After all, the flush statement could just have been manually added in foo.sage.

comment:5 Changed 11 years ago by rlm

  • Authors set to William Stein
  • Reviewers set to Robert Miller
  • Status changed from needs_review to positive_review

This is definitely an improvement, regardless. Let's get this merged.

comment:6 Changed 11 years ago by jdemeyer

  • Merged in set to sage-4.6.2.alpha1
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.