[Tutor] monitor number of files in a folder

Dave Angel davea at ieee.org
Thu Aug 6 23:12:14 CEST 2009


pedro wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">On 
> 2009-08-06 15:49:35 -0400, Wayne <srilyk at gmail.com> said:
>
>>
>>
>> On Thu, Aug 6, 2009 at 2:33 PM, pedro <pedrooconnell at gmail.com> wrote:
>>
>>> Hi I am rendering image sequences on a basic render farm that I am
>>> building. Once all the files in the sequence have been rendered I 
>>> would like
>>> to make a quicktime of the sequence automatically. The problem I am 
>>> having
>>> is that if one of the computers on the farm is rendering slow the 
>>> quicktime
>>> gets made before all the files are rendered.
>>>
>>> The variable below called "theNumberOfImages" is the actual # of images
>>> that have been rendered which is working fine.
>>> The variable below called "theNumberOfFrames" is the total # of 
>>> images that
>>> are supposed to be rendered. What I am trying to do but am not sure 
>>> how is
>>> to say:
>>> As soon as theNumberOfImages is equal to or greater than 
>>> theNumberOfFrames,
>>> render the quicktime.
>>>
>>> Here is my very bad solution
>>>
>>> if theNumberOfImages <= theNumberOfFrames:
>>> time.sleep(60)
>>> if theNumberOfImages <= theNumberOfFrames:
>>> time.sleep(60)
>>> if theNumberOfImages <= theNumberOfFrames:
>>> time.sleep(60)
>>> else:
>>> os.system('/Volumes/sgtb/lac/common/temp/theQuicktimeCommandTest.sh')
>>
>>
>> You really just want a  while loop:
>>
>> while imagecount >= framecount:
>>     time.sleep(60)
>>
>> # Call script here
>>
>> I guess that's the easiest way. Probably not the most effective, but 
>> I'm not
>> sure if the implementation of an alternate solution would be worth 
>> the cost.
>>
>> HTH,
>> Wayne
>>
>>
>> <br><br><div class=3D"gmail_quote">On Thu, Aug 6, 2009 at 2:33 PM, 
>> pedro <s=
>> pan dir=3D"ltr">&lt;<a 
>> href=3D"mailto:pedrooconnell at gmail.com">pedrooconnel=
>> l at gmail.com</a>&gt;</span> wrote:<br><blockquote 
>> class=3D"gmail_quote" styl=
>> e=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 
>> 0.8ex; =
>> padding-left: 1ex;">
>>
>> Hi I am rendering image sequences on a basic render farm that I am 
>> building=
>> . Once all the files in the sequence have been rendered I would like 
>> to mak=
>> e a quicktime of the sequence automatically. The problem I am having 
>> is tha=
>> t if one of the computers on the farm is rendering slow the quicktime 
>> gets =
>> made before all the files are rendered.<br>
>>
>>
>> <br>
>> The variable below called &quot;theNumberOfImages&quot; is the actual 
>> # of =
>> images that have been rendered which is working fine.<br>
>> The variable below called &quot;theNumberOfFrames&quot; is the total 
>> # of i=
>> mages that are supposed to be rendered. What I am trying to do but am 
>> not s=
>> ure how is to say:<br>
>> As soon as theNumberOfImages is equal to or greater than 
>> theNumberOfFrames,=
>>  render the quicktime.<br>
>> <br>
>> Here is my very bad solution<br>
>> <br>
>> if theNumberOfImages &lt;=3D theNumberOfFrames:<br>
>>  =A0 time.sleep(60)<br>
>>  =A0 if theNumberOfImages &lt;=3D theNumberOfFrames:<br>
>>  =A0 =A0 =A0 time.sleep(60)<br>
>>  =A0 =A0 =A0 if theNumberOfImages &lt;=3D theNumberOfFrames:<br>
>>  =A0 =A0 =A0 =A0 =A0 time.sleep(60)<br>
>> else:<br>
>>  =A0 
>> os.system(&#39;/Volumes/sgtb/lac/common/temp/theQuicktimeCommandTest.s=
>> h&#39;)</blockquote><div><br>You really just want a=A0 while 
>> loop:<br>=A0<b=
>> r>while imagecount &gt;=3D framecount:<br>=A0=A0=A0 
>> time.sleep(60)<br><br>#=
>>  Call script here<br>
>>
>> <br>I guess that&#39;s the easiest way. Probably not the most 
>> effective, bu=
>> t I&#39;m not sure if the implementation of an alternate solution 
>> would be =
>> worth the cost.<br><br>HTH,<br>Wayne<br></div></div><br>
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
> Hi Wayne, but if I do it that way won't it create an infinite loop if 
> the images don't all render?
> Pete
>
>
>
> </div>
>
(Please post as a text message when using mailing lists like this one.  
All that html junk clutters readability something awful.)


You have to choose your poison.  Your original approach (which you 
called "very bad") had the problem of only waiting 90 seconds max.  
Wayne's has the problem of waiting forever if some rendering aborts.  So 
you need to choose how much of a timeout, and what you want to do when 
you exceed it.   You also have the problem in this code that it's just 
checking variables, rather than calling a function that actually looks 
for the files.  And finally, I think the comparison operator isn't quite 
right (if I understand your two variables anyway).  Perhaps something like:

timeoutcount = 0
while filecount() < framecount and timeoutcount < 10:
    timeoutcount += 1
    time.sleep(30)

if filecount() < framecount:
   print "you lose, because it took longer than ", timeoutcount /2, 
"minutes"
else:
   os.system(....)




More information about the Tutor mailing list