Skip to content

Commit f04cdc1

Browse files
romain-intelNissan Pow
andauthored
fix for bad json file written out. (#2637)
Co-authored-by: Nissan Pow <npow@netflix.com>
1 parent e25fc10 commit f04cdc1

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

metaflow/runner/utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def read_from_fifo_when_ready(
109109
content = bytearray()
110110
poll = select.poll()
111111
poll.register(fifo_fd, select.POLLIN)
112-
max_timeout = 3 # Wait for 10 * 3 = 30 ms after last write
113112
while True:
114113
if check_process_exited(command_obj) and command_obj.process.returncode != 0:
115114
raise CalledProcessError(
@@ -137,15 +136,16 @@ def read_from_fifo_when_ready(
137136
else:
138137
# We had no events (just a timeout) and the read didn't return
139138
# an exception so the file is still open; we continue waiting for data
140-
# Unfortunately, on MacOS, it seems that even *after* the file is
141-
# closed on the other end, we still don't get a BlockingIOError so
142-
# we hack our way and timeout if there is no write in 30ms which is
143-
# a relative eternity for file writes.
144-
if content:
145-
if max_timeout <= 0:
146-
break
147-
max_timeout -= 1
148-
continue
139+
# On some systems (notably MacOS), even after the file is closed on the
140+
# other end, we may not get a BlockingIOError or proper EOF signal.
141+
# Instead of using an arbitrary timeout, check if the writer process
142+
# has actually exited. If it has and we have content, we can safely
143+
# assume EOF. If the process is still running, continue waiting.
144+
if content and check_process_exited(command_obj):
145+
# Process has exited and we got an empty read with no poll events.
146+
# This is EOF - break out to return the content we've collected.
147+
break
148+
# else: process is still running, continue waiting for more data
149149
except BlockingIOError:
150150
has_blocking_error = True
151151
if content:

0 commit comments

Comments
 (0)