Basically, it appears that if you open a pipe, then the main thread exits, other threads still running "stop begin able to write to that pipe" (my assumption is it was closed when the main thread exited). I think I've run into this before, but couldn't find a ticket for it easily, so sorry if it's a dupe. It seems to reproduce at least in windows 7 with jdk 1.6 and windows xp with jdk 7.
This snippet should output 'hello'
{{{
javax.swing.JFrame.new.show
a = IO.popen("jruby -e 'puts gets'", "w")
sleep 1 # let it start
timer = javax.swing.Timer.new(1000, nil)
timer.repeats=false # may not be necessary
timer.add_action_listener {
a.puts 'hello'
}
timer.start
- allow main thread to exit – uncomment the sleep line and it works as expected.
- sleep
}}}
as is, it responds with
Exception in thread "AWT-EventQueue-0" org.jruby.exceptions.RaiseException: (Errno::EBADF) Bad file descriptor
at org.jruby.RubyIO.write(org/jruby/RubyIO.java:1399)
at org.jruby.RubyIO.write(org/jruby/RubyIO.java:2376)
at org.jruby.RubyIO.puts(org/jruby/RubyIO.java:2331)
at org.jruby.RubyIO.puts(org/jruby/RubyIO.java:2323)
at bad.(root)(bad.rb:10)
at org.jruby.gen.InterfaceImpl1035124051.actionPerformed(org/jruby/gen/InterfaceImpl1035124051.gen:13)
or within a larger program:
Errno::EBADF: Bad file descriptor - Bad file descriptor
read at org/jruby/RubyIO.java:2904
` at file:/C:/installs/jruby-1.7.0/lib/jruby.jar!
/jruby/kernel/jruby/process_manager.rb:35
` at file:/C:/installs/jruby-1.7.0/lib/jruby.jar!
/jruby/kernel/jruby/process_manager.rb:49
set_all_ffmpegs_as_lowest_prio at C:/dev/dirt-simple-usb-surveillance/./lib/go
.rb:17
do_something at C:/dev/dirt-simple-usb-surveillance/./lib/go
.rb:99
IOError: Stream closed
The difficult thing with this is that the errors sometimes can manifest themselves "unreliably" because it depends if the main thread has exited yet or not. In my case, sometimes it has, sometimes it hasn't, which makes this a frustrating bug to trace.
Thanks!
roger
|