Skip to content

Commit b4486a8

Browse files
authored
Flush Utilities/bootstrap script logging output (#8141)
### Motivation: As `Utilities/helpers.py` output of `print` is not immediately flushed, it makes debugging of `Utilities/bootstrap` script very hard, since logging messages are not guaranteed to be printed in correct order. ### Modifications: All calls to `print` in `Utilities/helpers.py` have `flush=True` passed as arguments. ### Result: Messages logged in the bootstrap script are always printed in the correct order.
1 parent 5171ab8 commit b4486a8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Utilities/helpers.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
import errno
1919

2020
def log_timestamp(marker):
21-
print("--- %s: note: %s %s" % (os.path.basename(sys.argv[0]), marker, datetime.datetime.now().isoformat()))
21+
print("--- %s: note: %s %s" % (os.path.basename(sys.argv[0]), marker, datetime.datetime.now().isoformat()), flush=True)
2222

2323
def note(message):
24-
print("--- %s: note: %s" % (os.path.basename(sys.argv[0]), message))
24+
print("--- %s: note: %s" % (os.path.basename(sys.argv[0]), message), flush=True)
2525
log_timestamp("timestamp")
2626
sys.stdout.flush()
2727

2828
def error(message):
29-
print("--- %s: error: %s" % (os.path.basename(sys.argv[0]), message))
29+
print("--- %s: error: %s" % (os.path.basename(sys.argv[0]), message), flush=True)
3030
log_timestamp("timestamp")
3131
sys.stdout.flush()
3232
raise SystemExit(1)
@@ -51,21 +51,21 @@ def mkdir_p(path):
5151
def call(cmd, cwd=None, verbose=False):
5252
"""Calls a subprocess."""
5353
if verbose:
54-
print(' '.join(cmd))
54+
print(' '.join(cmd), flush=True)
5555
try:
5656
subprocess.check_call(cmd, cwd=cwd)
5757
except Exception as e:
5858
if not verbose:
59-
print(' '.join(cmd))
59+
print(' '.join(cmd), flush=True)
6060
error(str(e))
6161

6262
def call_output(cmd, cwd=None, stderr=False, verbose=False):
6363
"""Calls a subprocess for its return data."""
6464
if verbose:
65-
print(' '.join(cmd))
65+
print(' '.join(cmd), flush=True)
6666
try:
6767
return subprocess.check_output(cmd, cwd=cwd, stderr=stderr, universal_newlines=True).strip()
6868
except Exception as e:
6969
if not verbose:
70-
print(' '.join(cmd))
70+
print(' '.join(cmd), flush=True)
7171
error(str(e))

0 commit comments

Comments
 (0)