Do not run proc.communicate on terminated process

If proc.returncode is not None, process has already terminated,
and running proc.communicate() will result in an exception:
ValueError: I/O operation on closed file
Do not run proc.communicate on terminated process

If proc.returncode is not None, process has already terminated,
and running proc.communicate() will result in an exception:
ValueError: I/O operation on closed file