janlelis/unicode-display_width

Cannot be used in a trap

jrmhaig opened this issue · 1 comments

This gem cannot be used in Signal trap. For example run this:

require 'unicode/display_width'

Signal.trap('USR1') do
  puts Unicode::DisplayWidth.of("⚀")
end

puts Process.pid
sleep(60)

and then execute:

kill -USR1 <process id>

This crashes with the error:

unicode-display_width/lib/unicode/display_width.rb:6:in `require_relative': can't be called from trap context (ThreadError)

I would suggest moving the require_relative to the top so that the file is loaded at the start rather than dynamically.

Thank you for the bug report. The dynamic loading of the index dates back to when the index size was rather big, which is not the case anymore. So I followed your suggestion and released 1.1.1, which loads the index at start-up time.