Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53252 > unrolled thread

RE: subprocess.Popen instance hangs

Started by"Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid>
First post2013-08-29 18:49 +0000
Last post2013-08-29 18:49 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  RE: subprocess.Popen instance hangs "Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid> - 2013-08-29 18:49 +0000

#53252 — RE: subprocess.Popen instance hangs

From"Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid>
Date2013-08-29 18:49 +0000
SubjectRE: subprocess.Popen instance hangs
Message-ID<mailman.369.1377803842.19984.python-list@python.org>
Tim Johnson
> using Python 2.7.1 on OS X 10.7.5
> 
> I'm managing a process of drush using an instance of subprocess.Popen
> 
> The process has a '--verbose' option. When that option is passed as
> part of the initializer `args' argument, the process will hang.
> 
> It should be no surprise as drush output with the --verbose option
> can be _extremely_ verbose, and I can do without it, but I would
> like to learn how to handle it. I've googled this topic, but my poor
> little brain is yet to sort out all of the content found.
> 
> ## my relevant code follows :
> p = subprocess.Popen(args,stderr=subprocess.STDOUT,stdout=subprocess.PIPE)
> ## wait() is 'forever' if '--verbose' used
> exit_status = p.wait()
> output = p.stdout.read()
> ## done
> 
> I 'suspect' that using a tempfile may be the solution, if so, I
> could use some examples.
> 
> thanks
> --
> Tim
> tim at tee jay forty nine dot com or akwebsoft dot com
> http://www.akwebsoft.com
> --


I think the documentation covers your issue. 

"""
Popen.wait()
    Wait for child process to terminate. Set and return returncode attribute.
    Warning: will deadlock when using stdout=PIPE and/or stderr=PIPE and the child 
    process generates enough output to a pipe such that it blocks waiting for the 
    OS pipe buffer to accept more data. Use [Popen.]communicate() to avoid that.
""" From http://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait

Does switching to `p.communicate()` solve your problem?


~Ramit



This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email.  

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web