The results look right! I did a rather large test and the checksum passed. <div><br></div><div>I will hold off any speed ups as you suggested.<br><br><div class="gmail_quote">On Wed, Feb 23, 2011 at 8:37 PM, Rob Williscroft <span dir="ltr"><<a href="mailto:rtw@rtw.me.uk">rtw@rtw.me.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Rita wrote in<br>
news:AANLkTi=<a href="mailto:88dCPM_kqRs2g620OBsNXz0maJUbfWPEmEtnL@mail.gmail.com">88dCPM_kqRs2g620OBsNXz0maJUbfWPEmEtnL@mail.gmail.com</a> in<br>
gmane.comp.python.general:<br>
<br>
[Top post relocated]<br>
<div><div></div><div class="h5"><br>
> On Tue, Feb 22, 2011 at 7:57 PM, Rob Williscroft <<a href="mailto:rtw@rtw.me.uk">rtw@rtw.me.uk</a>><br>
> wrote:<br>
><br>
>> Rita wrote in<br>
>> news:AANLkTi=<a href="mailto:w95gXoSc1TKt2BntGjqys1cbmDnoJHOKQ4YBA@mail.gmail.com">w95gXoSc1TKt2BntGjqys1cbmDnoJHOKQ4YBA@mail.gmail.com</a> in<br>
>> gmane.comp.python.general:<br>
>><br>
>> ><br>
>> > When using wait() it works a bit better but not consistent<br>
>> > def run(cmd):<br>
>> >   p=subprocess.Popen(cmd,stdout=subprocess.PIPE)<br>
>> >   rc=p.wait()<br>
>> >   print rc<br>
>> >   return p.stdout<br>
>> ><br>
>><br>
>> > When the output of cmd is a small ascii file it works perfectly<br>
>> > fine, but when the file is large (more than 2MB) the process just<br>
>> > waits for ever (I am guessing its blocking?).<br>
>><br>
>> Your OS has supplied a pipe buffer of 2MB, its full and the prossess<br>
>> is waiting until you read something from the pipe (i.e.<br>
>> p.stdout.read()).<br>
>><br>
>> >            When I use the communicate call<br>
>> > it works perfectly but my process is consuming way too much memory.<br>
>> ><br>
>> > Is there a better way to get my return code consistently<br>
>> > efficiently and not take up so much memory?<br>
>><br>
>> If you don't need the processes output then don't use the PIPE<br>
>> argument. If you do you will need to read from p.stdout until the<br>
>> process is complete, then get the return code:<br>
>><br>
>> while True:<br>
>>        buf = p.stdout.read( 1024 )<br>
>>        # do somthing with buf<br>
>>        if len( buf ) < 1024:<br>
>>                break<br>
>><br>
>> rc = p.wait()<br>
<br>
><br>
> For extra points is there a way to speed up the p.stdout.read(bufsize)<br>
> ?<br>
<br>
</div></div>Its unlikely that is the problem, most likely you are reading all of the<br>
2MB OS pipe buffer and then having to wait for the programme you are<br>
calling to produce some more output.<br>
<br>
Before trying to speed things up be sure to test with real work being<br>
done to the output you recieve.<br>
<br>
If its still slow and you have multiple cores/processors then you will<br>
need to put you read loop in a thread to speed it up.<br>
<font color="#888888"><br>
--<br>
</font><div><div></div><div class="h5">Rob.<br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>--- <span>Get your facts first, then you can distort them as you please.</span>--<br>
</div>