From: Michael Neumann Date: 2000-07-14T14:22:24+02:00 Subject: [ruby-talk:04009] Re: Thread and File do not work together From: "Yukihiro Matsumoto" > [...] > Thread.start creates new thread and fork it, then readline meets EOF > and raise error in the main thread. When the main thread terminates > whole process (including forked thread) be terminated too. > > Thread.start { > print "ok\n" > print File::readlines("index.htm").to_s > }.join > readline > > will change the situation. > > matz. > Thanks, this works but is not what I want. This would be exactly the same like using no threads, isn't it? It seems to me that I cannot read from files inside a thread. If I do so, the thread terminates. Following example hangs, if I try to read from a file: require "socket" gs = TCPServer.open(1000) while true ns = gs.accept print(ns, " is accepted\n") Thread.start do s = ns # save to dynamic variable while s.gets s.write($_) f = File::open("ib_test.rb") print "before\n" f.gets # here the thread terminates/hangs print "after\n" end print(s, " is gone\n") s.close end end --- Michael