Skip to content

Commit 0be255d

Browse files
committed
Debug sub_process interaction
1 parent 92a42c5 commit 0be255d

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/utils/cmd.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import subprocess
1515
import textwrap
16+
import time
1617
import uuid
1718

1819
# Import third party modules
@@ -359,12 +360,33 @@ def run_subprocess(
359360
if expect:
360361

361362
# Run as long as the process is running, and the expect list still has values
362-
while not sub_process.poll() and len(expect) > 0:
363+
while True:
364+
365+
if sub_process.poll():
366+
log(ctx, f"sub_process.poll(): {sub_process.poll()}", "debug")
367+
break
368+
369+
if sub_process.returncode:
370+
log(ctx, f"sub_process.returncode: {sub_process.returncode}", "debug")
371+
break
372+
373+
if len(expect) <= 0:
374+
log(ctx, f"len(expect) <= 0: {len(expect)}", "debug")
375+
break
376+
377+
# The child process was reaped with exit code 1, but it seems like this loop keeps going forever?
378+
379+
log(ctx, "here", "debug")
380+
log_process_status(ctx, subprocess_psutils_dict, subprocess_dict)
363381

364382
# Try to read a line of output
365-
# Potential problem: this waits for a \n
383+
# Potential problems:
384+
# This waits for a \n
385+
# This may cause a deadlock
366386
early_output = sub_process.stdout.readline()
367387

388+
log(ctx, f"early_output: {early_output}", "debug")
389+
368390
# If there is output
369391
if early_output:
370392

@@ -389,6 +411,9 @@ def run_subprocess(
389411
# Skip any of the prompts / responses remaining in the list, for this line of output
390412
break
391413

414+
# Sleep a second, just to stop an infinite loop from consuming infinite CPU
415+
time.sleep(1)
416+
392417

393418
if password:
394419

0 commit comments

Comments
 (0)