Skip to content

Commit

Permalink
Merge pull request #49 from PyUtilib/subprocess_th_fix
Browse files Browse the repository at this point in the history
Fix UnboundLocalError (subprocess died before reader threads started).
  • Loading branch information
jsiirola authored Jan 16, 2019
2 parents 89086c2 + 85b13d0 commit fe7a4b0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pyutilib/subprocess/processmngr.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ def run_command(cmd,
simpleCase = False

out_th = []
th = None
GlobalData.signal_handler_busy = False
if simpleCase:
#
Expand Down Expand Up @@ -687,10 +688,16 @@ def run_command(cmd,
#
for p in out_th:
os.close(p[2])
th.join()
if th is not None:
# Note, there is a condition where the subprocess can die
# very quickly (raising an OSError) before the reader
# threads have a chance to be set up. Testing for None
# avoids joining a thread that doesn't exist.
th.join()
for p in out_th:
os.close(p[1])
del th
if th is not None:
del th
if outfile is not None:
stdout_arg.close()
elif tmpfile is not None and not ignore_output:
Expand Down

0 comments on commit fe7a4b0

Please sign in to comment.