FAQ
I'm running python 2.5 and have bumped into an issue whereby the PIPE
in subprocess.Popen locks up after taking too many characters. I found
some documentation that discuss this problem and offers some ideas for
solutions, the best one being to pass a file object into subprocess
instead of PIPE. This will allow for much larger std output.

http://thraxil.org/users/anders/posts/2008/03/13/Subprocess-Hanging-PIPE-is-your-enemy/

The problem is that, while I can pass in a tempfile.TemporaryFile() and
everything seems to go swimmingly, there doesn't seem to be anything
written to file I handed Popen.

import tempfile
import subprocess

def awesome():
# I understand that not everyone has nuke, but it doesn't seem to
matter what I run through it
# the result is the same.
my_cmd = '/usr/local/Nuke6.0v3/Nuke6.0 -V'

my_stderr = tempfile.TemporaryFile()
my_stdout = tempfile.TemporaryFile()

process = subprocess.Popen(my_cmd, stderr=my_stderr, stdout=my_stdout)
process.wait()

print my_stderr.read()
print my_stdout.read()

print "Finished!!!"

Any help on this issue would be awesome! thanks!

Brandon L. Harris

Search Discussions

  • Antoine Pitrou at Nov 4, 2010 at 10:39 pm

    On Thu, 04 Nov 2010 17:13:09 -0500 Brandon Harris wrote:
    I'm running python 2.5 and have bumped into an issue whereby the PIPE
    in subprocess.Popen locks up after taking too many characters. I found
    some documentation that discuss this problem and offers some ideas for
    solutions, the best one being to pass a file object into subprocess
    instead of PIPE.
    This sounds rather unlikely. Have you used communicate()?
    process = subprocess.Popen(my_cmd, stderr=my_stderr, stdout=my_stdout)
    process.wait()

    print my_stderr.read()
    print my_stdout.read()
    Try to rewind the file pointer before reading from it.

    Regards

    Antoine.
  • Brandon Harris at Nov 4, 2010 at 10:49 pm
    What do you mean by rewind the file pointer before reading from it?
    Seek back to the beginning? And It sounded very unlikely to me too, but
    it's the only thing I have found that explains why a very verbose job
    with tons of feedback locks up at the same point and won't process at all.

    I did try running communicate before and after the wait() but to no avail.

    Brandon L. Harris

    On 11/04/2010 05:39 PM, Antoine Pitrou wrote:
    Try to rewind the file pointer before reading from it.
  • Brandon Harris at Nov 4, 2010 at 10:57 pm
    ok. Jumping back to the start of the file solved the problem.
    (file.seek(0)) Big thanks for that insight!

    Brandon L. Harris

    On 11/04/2010 05:49 PM, Brandon Harris wrote:
    What do you mean by rewind the file pointer before reading from it?
    Seek back to the beginning? And It sounded very unlikely to me too,
    but it's the only thing I have found that explains why a very verbose
    job with tons of feedback locks up at the same point and won't process
    at all.

    I did try running communicate before and after the wait() but to no
    avail.

    Brandon L. Harris

    On 11/04/2010 05:39 PM, Antoine Pitrou wrote:
    Try to rewind the file pointer before reading from it.
  • Christian Heimes at Nov 4, 2010 at 11:59 pm

    Am 04.11.2010 23:49, schrieb Brandon Harris:
    What do you mean by rewind the file pointer before reading from it?
    Seek back to the beginning? And It sounded very unlikely to me too, but
    it's the only thing I have found that explains why a very verbose job
    with tons of feedback locks up at the same point and won't process at all.
    Look at a file handler like an old style magnetic tape. You just have
    recorded your favorite song from radio onto a tape. What do you have to
    do in order to listen to the song again? Press play? No, you have to
    rewind first.

    The MP3 generation will never understand the hard work of a mix tape
    created recorded from radio broadcasts. ;)

    Christian

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 4, '10 at 10:13p
activeNov 4, '10 at 11:59p
posts5
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase