在您发布的代码中没有看到问题,我猜您正在循环打开多个文件,并且无法关闭它们,
fun foo _ 0 = ()
| foo filenm n = let val _ = TextIO.openIn(filenm) in foo filenm (n - 1) end
fun bar _ 0 = ()
| bar filenm n =
let val ins = TextIO.openIn(filenm)
val _ = TextIO.inputLine(ins)
val _ = TextIO.closeIn(ins)
in bar filenm (n - 1) end
在以下脚本中,对bar的调用使用 1024,因为它依次打开然后关闭每个输入流,但是随后对foo的调用失败并出现错误,因为它达到了平台定义的打开文件描述符数量的限制。
val foo = fn : string -> int -> unit
val bar = fn : string -> int -> unit
- bar "toomanyfiles.sml" 1024;
val it = () : unit
- foo "toomanyfiles.sml" 1024;
uncaught exception Io [Io: openIn failed on "toomanyfiles.sml", Too many open files]
raised at: Basis/Implementation/IO/text-io-fn.sml:783.25-783.71