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:
(define (test-fn)
(define (do-process)
(with-input-from-process (list path: "pwd") read-all))
(let loop [(count 2000)]
(if (> count 0)
(begin
(do-process)
(loop (- count 1)))
(println "Done"))))
(test-fn)
And the output:
bigmac:iosTexConverter aking$ gsc -v
v4.6.1 20110519175028 i386-apple-darwin10.8.0 "./configure
/usr/local/Gambit-C/share/config.site /usr/local/Gambit-C/etc/config.site"
bigmac:iosTexConverter aking$ gsi ./test.scm
*** ERROR IN loop, "test.scm"@9.11 -- Too many open files
(with-input-from-process '(path: "pwd") '#<procedure #2 read-all>)
bigmac:iosTexConverter aking$
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?