Skip to content

Commit

Permalink
Flushing the stdout line of the vap lines count makes the duration ca…
Browse files Browse the repository at this point in the history
…lculation much faster
  • Loading branch information
NickSwainston committed Nov 13, 2023
1 parent 5a304a8 commit 1d50959
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions psrdb/scripts/generate_meerkat_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,22 @@ def get_sf_length(sf_files):
"""
comm = f"vap -c length {' '.join(sf_files)}"
args = shlex.split(comm)
proc = subprocess.Popen(args,stdout=subprocess.PIPE)
proc.wait()
vap_lines = proc.stdout.read().decode("utf-8").split("\n")
proc = subprocess.Popen(args, stdout=subprocess.PIPE, text=True, bufsize=1)
vap_lines = []
try:
# Read and process the output line by line in real-time
for line in iter(proc.stdout.readline, ''):
print(line, end='', flush=True)
vap_lines.append(line)

# Handle Ctrl+C to gracefully terminate the subprocess
except KeyboardInterrupt:
logging.error("Process interrupted. Terminating...")
sys.exit(1)

finally:
# Wait for the subprocess to complete
proc.wait()

lengths = []
for line in vap_lines[1:]:
Expand Down

0 comments on commit 1d50959

Please sign in to comment.