I need to descend a directory structure with ~5000 files in it and run an external process on each to gether information on each file.  However, after running over about 250 files, I get a "Too many open files" error.  250 is probably OSX default max open file limit - but I don't understand why the 'with-input-from-process' doesn't appear to be closing its file handle?  I also tried with 'open-input-process' and 'open-process' and manually calling 'close-input-port' but didn't help.  Here's a small script that shows the exact same prob:<div>
<br></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font face="'courier new', monospace">(define (test-fn)</font></div></div><div><div><font face="'courier new', monospace">  </font></div>
</div><div><div><font face="'courier new', monospace">  (define (do-process)</font></div></div><div><div><font face="'courier new', monospace">    (with-input-from-process (list path: "pwd") read-all))</font></div>
</div><div><div><font face="'courier new', monospace"><br></font></div></div><div><div><font face="'courier new', monospace">  (let loop [(count 2000)]</font></div></div><div><div><font face="'courier new', monospace">    (if (> count 0)</font></div>
</div><div><div><font face="'courier new', monospace">        (begin</font></div></div><div><div><font face="'courier new', monospace">          (do-process)</font></div></div><div><div><font face="'courier new', monospace">          (loop (- count 1)))</font></div>
</div><div><div><font face="'courier new', monospace">        (println "Done"))))</font></div></div><div><div><font face="'courier new', monospace"><br></font></div></div><div><div><font face="'courier new', monospace"><br>
</font></div></div><div><div><font face="'courier new', monospace">(test-fn)</font></div></div><div><font face="'courier new', monospace"><br></font></div></blockquote><font face="arial, helvetica, sans-serif">And the output:</font><div>
<font face="arial, helvetica, sans-serif"><br></font></div><div><div>bigmac:iosTexConverter aking$ gsc -v</div><div>v4.6.1 20110519175028 i386-apple-darwin10.8.0 "./configure /usr/local/Gambit-C/share/config.site /usr/local/Gambit-C/etc/config.site"</div>
<div><br></div><div>bigmac:iosTexConverter aking$ gsi ./test.scm </div><div>*** ERROR IN loop, "test.scm"@9.11 -- Too many open files</div><div>(with-input-from-process '(path: "pwd") '#<procedure #2 read-all>)</div>
<div>bigmac:iosTexConverter aking$ </div></div><div><br></div><div>Running latest from the Gambit git repo and OSX 10.6.8.  As far as I can tell, calling 'pwd' shouldn't be leaving around open file handles.  I also checked the process-status, and it was 0.  Any suggestions?</div>