python - Using subprocess.Popen for Process with Large Output -


There is nothing left to do. My code looks like this:

  p = subprocess.Popen (cmd, shell = true, stdout = subprocess.PIPE, stderr = subprocess.PIPE) errcode = p.wait () rate = p . Stdout.read () errmess = p.stderr.read () if errcode: log.error ('cmd is unsuccessful & lt;% s & gt;:% s'% (errcode, errmess))  

Docs has comments that indicate a potential problem. Waiting, there is:

WARNING: If the child process generates enough output in a stdout or stderr pipe, then this deadlock It will be waiting for the OS to accept more data for pipe buffer.

Note: Read Data Storage In Buffer, so if the size of this data is large or unlimited, then do not use this method.

So it is unclear to me that I should use any of these if I have too much data they do not indicate which method I should use in that situation.

I need the return value from exec and parse and both stdout and stderr .

So what is the equivalent method in python to run an external app that is going to achieve larger output?

You are blocking two files; The first thing that needs to be completed before it starts is if the application writes a lot for the stderr, and there is nothing for stdout, then your process is waiting for the data coming on stdout which is not coming, While the program you are running is waiting for the stuff you are sitting there who read stderr (which will never happen - because you are waiting for stdout).

There are some ways you can fix this.

The easiest way to stop stderr; Leave stderr = None Errors will output directly to the staircase. You can not stop them and display them as part of your message. For command line equipment, this is often okay. For other apps, this may be a problem.

Another simple method is to redirect stderr to stdout, so you only have one incoming file: set stderr = STDOUT This means that you can not separate regular output from error output. How it can not be acceptable, depends on how the application writes output.

This is the complete and complex way selection to handle (). This requires you to read in a non-intercepting way: Whenever the data appears on stdout or stderr, you get the data. I only recommend it if it is really necessary it probably does not work in Windows.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -