vmsnomad
Joined: 30 Jul 2015 Posts: 1
|
Posted: Thu Jul 30, 2015 8:34 am Post subject: subprocess.Popen hangs when command returns error |
|
|
vmspython: 2.7.8 (running off LD images)
system: OpenVMS V7.3-2 Alpha
ISSUE: When a subprocess.Popen-spawned command results in error and subprocess.Popen redirects are used, the scripts never terminates.
Here's the script and its output to test this issue:
Code: | import subprocess
cmd = "show default xx" ## hangs before termination (needs Ctrl/Y)
## cmd = "show default" ## terminates cleanly
print("BEGIN:%s" % cmd)
p = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
print("out:%s" % out)
print("err:%s" % err)
print("END:%s" % cmd)
-----------------------------
OUTPUT:
BEGIN:show default xx
out:
err:%DCL-W-MAXPARM, too many parameters - reenter command with fewer parameters
END:show default xx
...hangs indefinitely.....
-----------------------------
DCL:
$ sh def xx
%DCL-W-MAXPARM, too many parameters - reenter command with fewer parameters
\XX\
|
NOTE: Only the first line of the actual DCL error is returned via Popen. The python script does not return to prompt. After Ctrl/Y, the spawned subprocess remains active (LEF).
This issue occurs with any other spawned command/image/procedure that results in a non-successful status.
This seems to be related to subprocess.PIPE/communicate, as when called simply as subprocess.Popen(cmd) it terminates cleanly.
NOTE2: You may notice a consistent delay before the out/err: is displayed. This is unlike the successful command completion which is rather snappy. Judging from the subprocess.py internals this amounts to some timing logic when reading stdout and stderr mailboxes.
At this point I exhaused my debugging ideas and would appreciate your insights, better yet a fix for this issue. |
|