forum.vmspython.org Forum Index forum.vmspython.org
Forum system
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

subprocess.Popen hangs when command returns error

 
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS
View previous topic :: View next topic  
Author Message
vmsnomad



Joined: 30 Jul 2015
Posts: 1

PostPosted: Thu Jul 30, 2015 8:34 am    Post subject: subprocess.Popen hangs when command returns error Reply with quote

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.
Back to top
View user's profile Send private message
jfp



Joined: 12 Jul 2004
Posts: 618

PostPosted: Mon Aug 10, 2015 9:42 am    Post subject: Reply with quote

Thanks for reporting.

You can try to add
Code:
p.kill()

after the last print, this seem to work on my Itanium box.

JF
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group