.. | .. |
---|
60 | 60 | |
---|
61 | 61 | |
---|
62 | 62 | def main(): |
---|
63 | | - args = parse_arguments() |
---|
| 63 | + try: |
---|
| 64 | + args = parse_arguments() |
---|
64 | 65 | |
---|
65 | | - lock = multiprocessing.Lock() |
---|
66 | | - pool = multiprocessing.Pool(initializer=init, initargs=(lock, args)) |
---|
67 | | - # Read JSON data into the datastore variable |
---|
68 | | - with open(args.path, "r") as f: |
---|
69 | | - datastore = json.load(f) |
---|
70 | | - pool.map(run_analysis, datastore) |
---|
| 66 | + lock = multiprocessing.Lock() |
---|
| 67 | + pool = multiprocessing.Pool(initializer=init, initargs=(lock, args)) |
---|
| 68 | + # Read JSON data into the datastore variable |
---|
| 69 | + with open(args.path, "r") as f: |
---|
| 70 | + datastore = json.load(f) |
---|
| 71 | + pool.map(run_analysis, datastore) |
---|
| 72 | + except BrokenPipeError: |
---|
| 73 | + # Python flushes standard streams on exit; redirect remaining output |
---|
| 74 | + # to devnull to avoid another BrokenPipeError at shutdown |
---|
| 75 | + devnull = os.open(os.devnull, os.O_WRONLY) |
---|
| 76 | + os.dup2(devnull, sys.stdout.fileno()) |
---|
| 77 | + sys.exit(1) # Python exits with error code 1 on EPIPE |
---|
71 | 78 | |
---|
72 | 79 | |
---|
73 | 80 | if __name__ == "__main__": |
---|