From: "Ara.T.Howard" Date: 2004-02-26T02:04:53+09:00 Subject: Re: io/nonblock - blocks w/threads? On Wed, 25 Feb 2004, Robert Klemme wrote: > > Some answers - but not all... thanks for the response... > That's an interesting question. One would rather expect > "Thread.critical=true" to block the whole process. I guess, that there are > no thread context changes without these methods and assigning to > Thread.critical has the side effect of doing a context switch if possible. > I'd try to use "Thread.pass" after "l.configure..." instead of > "Thread.critical" to give other threads a chance to run and see what > happens. > > > b) is this approach (critical section) the correct way of dealing with > this > > issue? > > If the blocking is indeed caused by the loop spinning endlessly, Thread.pass > is a far better alternative. You could as well use sleep to achieve the > same. it's the actual call to nonblock that blocks the process, try this using the two different approaches between the print statements: require 'tk' require 'open3' require 'io/nonblock' require 'thread' $VERBOSE=nil STDOUT.sync = STDERR.sync = true r=TkRoot.new l=TkLabel.new r, :text=>`ruby -e "p Time.now"` l.pack command='ruby -e "loop{p Time.now; sleep 1}"' i,o,e = Open3::popen3 command i.close text = nil Thread.new do loop do rios, = select [o, e], nil, nil rios.map do |rio| next if rio.eof? p 'start...' rio.nonblock{ text = rio.read } # blocks #text = rio.gets # does not block p 'finish' l.configure :text=>text end end end Tk.mainloop i also tried a couple of ways on inserting Thread.pass - outside of nonblock's block, inside of it, etc. - nothing works except protecting the call to read by critical/exclusive which does really make sense since the point of nonblock is not to? -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | URL :: http://www.ngdc.noaa.gov/stp/ | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done ===============================================================================