【发布时间】:2020-10-23 22:56:27
【问题描述】:
我正在尝试使用多个线程写入文本文件,但是下面的代码给了我一个异常 - IOError: closed stream
threads = []
File.open("test.txt", "a") do |fp|
500.times do |time|
threads << Thread.new do
fp.puts("#{time}: 1")
sleep(rand(100) / 100.0)
fp.puts("#{time}: 2")
end
end
end
threads.each{ |thread| thread.join }
【问题讨论】:
标签: jruby