A follow-up, for ruby 1.9.0 (2008-03-01 revision 0) [i686-linux].

It seems the blocking issue is gone, but now flock'ing with
File::LOCK_NB returns 0 regardless of whether the file can be locked.
Example irb session below:

irb(main):001:0> f = File.new('foo')
=> #<File:foo>
irb(main):002:0> f.flock(File::LOCK_EX)
=> 0
irb(main):003:0> f2 = File.new('foo')
=> #<File:foo>
irb(main):004:0> f2.flock(File::LOCK_EX | File::LOCK_NB)
=> 0
irb(main):005:0> f2.flock(File::LOCK_EX)
(...hangs, aborting with Ctl-C...)
IRB::Abort: abort then interrupt!!
        from /usr/local/lib/ruby/1.9.0/irb.rb:80:in `irb_abort'
        from /usr/local/lib/ruby/1.9.0/irb.rb:246:in `signal_handle'
        from /usr/local/lib/ruby/1.9.0/irb.rb:65:in `block in start'
        from (irb):5:in `flock'
        from (irb):5
        from /usr/local/lib/ruby/1.9.0/irb.rb:149:in `block (2 levels)
in eval_input'
        from /usr/local/lib/ruby/1.9.0/irb.rb:262:in `signal_status'
        from /usr/local/lib/ruby/1.9.0/irb.rb:146:in `block in
eval_input'
        from /usr/local/lib/ruby/1.9.0/irb.rb:145:in `eval_input'
        from /usr/local/lib/ruby/1.9.0/irb.rb:69:in `block in start'
        from /usr/local/lib/ruby/1.9.0/irb.rb:68:in `catch'
        from /usr/local/lib/ruby/1.9.0/irb.rb:68:in `start'
        from /usr/local/bin/irb-1.9:12:in `<main>'
irb(main):006:0> f.flock(File::LOCK_UN)
=> 0
irb(main):007:0> f2.flock(File::LOCK_EX)
=> 0
irb(main):008:0>

-Lin

On Feb 27, 5:51 pm, ts <dec... / moulon.inra.fr> wrote:
> >>>>> "l" == llin  <chee... / gmail.com> writes:
>
> l> I'm having trouble getting File.flock to work in non-blocking mode, in
> l> ruby 1.9.0 (on CentOS 5).  The same code (show below in irb session)
> l> works in ruby 1.8.5, but in 1.9.0 the attempt to lock in non-blocking
> l> mode will block.  Has anyone else experienced this?  Any help or
> l> suggestions would be much appreciated!
>
>  The problem is that 1.8.6 test if LOCK_NB was given, or if ruby has only
>  one thread when it call flock(2), what not do apparently 1.9. Is this
>  volontary ?
>
> Guy Decoux