[Win32utils-devel] Signal#trap problems

Heesob Park phasis at gmail.com
Sun Feb 12 12:29:18 UTC 2012


Hi,

2012/2/12 Daniel Berger <djberg96 at gmail.com>

> Hi all,
>
> This is supposed to work, right? It works on 1.8.7 for me, but not
> 1.9.2 or 1.9.3:
>
> handle = File.open('trap_test.txt', 'w+')
>
> Signal.trap('ABRT'){ handle.print('hello') }
> Process.kill('ABRT', Process.pid)
>
> handle.rewind
> p handle.read # => "hello" with 1.8.7, empty string with 1.9.x and JRuby
> handle.close
>
> Do I need to submit a bug report?
>
> I guess it is not a bug but a timing problem.

Here is a modified version working for 1.8.7 and 1.9.3:

handle = File.open('trap_test.txt', 'w+')
Signal.trap('ABRT'){ handle.print('hello') }
Thread.new { Process.kill('ABRT', Process.pid) }
sleep 1
handle.rewind
p handle.read
handle.close


Regards,

Park Heesob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/win32utils-devel/attachments/20120212/044edb8a/attachment.html>


More information about the win32utils-devel mailing list