Skip to content

Commit

Permalink
Fix UnboundLocalError (subprocess died before reader threads started).
Browse files Browse the repository at this point in the history
This resolves an exception that is due to a timing error where a
subprocess can die before the O/I reader threads are launched.  The
cleanup routines need to verify that the threads were created before
joining them.
  • Loading branch information
jsiirola committed Jan 16, 2019
1 parent 89086c2 commit 85b13d0
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 85b13d0

Please sign in to comment.