Skip to content

Commit 9b41ab4

Browse files
committed
Eliminate exception at process end
1 parent b8a45e5 commit 9b41ab4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

source-code/processes/monitor.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def main():
158158
inactive.extend(('read_files', 'write_files'))
159159
metrics = define_actions(inactive)
160160
file = open(options.output_file, 'w') if options.output_file else sys.stdout
161+
found_process = False
161162
try:
162163
with file:
163164
print(status_header(metrics), file=file)
@@ -167,10 +168,16 @@ def main():
167168
process_status(child_process, metrics)
168169
for child_process in process.children(recursive=True)
169170
)
170-
print('\n'.join(process_info), file=file)
171+
print('\n'.join(process_info), file=file, flush=True)
172+
found_process = True
171173
time.sleep(options.delta)
172174
except KeyboardInterrupt:
173175
pass
176+
except psutil.NoSuchProcess:
177+
if not found_process:
178+
print(f'Process {options.pid} does not exist', file=sys.stderr)
179+
return 1
180+
return 0
174181

175182

176183
if __name__ == '__main__':

0 commit comments

Comments
 (0)