Skip to content

Commit 5cfb27e

Browse files
committed
chore: make set_edge_weights.py play well with pipes
1 parent 908cc35 commit 5cfb27e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

set_edge_weights.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import argparse
44
import csv
55
import logging
6+
import os
67
import pathlib
78
import sys
89
import typing
@@ -89,8 +90,15 @@ def main():
8990
edge_sizes = get_edge_sizes(include_analysis, config.includeDirs if config else None)
9091
csv_writer = csv.writer(sys.stdout)
9192

92-
for row in set_edge_weights(args.changes_file, edge_sizes):
93-
csv_writer.writerow(row)
93+
try:
94+
for row in set_edge_weights(args.changes_file, edge_sizes):
95+
csv_writer.writerow(row)
96+
97+
sys.stdout.flush()
98+
except BrokenPipeError:
99+
devnull = os.open(os.devnull, os.O_WRONLY)
100+
os.dup2(devnull, sys.stdout.fileno())
101+
sys.exit(1)
94102

95103
return 0
96104

0 commit comments

Comments
 (0)