This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.
I had an issue at work where some database writes were throwing errors within a thread, and the error was being silently eaten when the thread died. The solution is to use a queue for inter-thread communication, like this: q = Queue.new Thread.new do i = 1 loop do begin sleep i i += 1 raise 'whatever' rescue StandardError => e q << e end end end loop do puts q.size end
I had an issue at work where some database writes were throwing errors within a thread, and the error was being silently eaten when the thread died.
The solution is to use a queue for inter-thread communication, like this:
q = Queue.new
Thread.new do
i = 1
loop do
begin
sleep i
i += 1
raise 'whatever'
rescue StandardError => e
q << e
end
end
end
loop do
puts q.size
end
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.