commit dd736147ca5dd657c40041c237e89eb41bbace87
parent 4373f679320b906d4af071ccc5cbed56a865c519
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date: Sun, 10 Dec 2006 19:41:43 +0000
unified reporting of thread exceptions
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@71 5c8cc53c-5e98-4d25-b20a-d8db53a31250
Diffstat:
4 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/bin/sup b/bin/sup
@@ -7,6 +7,17 @@ require "sup"
module Redwood
$exception = nil
+def reporting_thread
+ ::Thread.new do
+ begin
+ yield
+ rescue Exception => e
+ $exception ||= e
+ raise
+ end
+ end
+end
+module_function :reporting_thread
global_keymap = Keymap.new do |k|
k.add :quit, "Quit Redwood", 'q'
@@ -109,7 +120,7 @@ begin
bm.draw_screen
imode.load_more_threads ibuf.content_height
- ::Thread.new { sleep 3; PollManager.poll }
+ reporting_thread { sleep 3; PollManager.poll }
until $exception
bm.draw_screen
diff --git a/lib/sup/modes/label-list-mode.rb b/lib/sup/modes/label-list-mode.rb
@@ -18,7 +18,7 @@ class LabelListMode < LineCursorMode
def load; regen_text; end
def load_in_background
- ::Thread.new do
+ Redwood::reporting_thread do
regen_text do |i|
if i % 10 == 0
buffer.mark_dirty
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
@@ -265,14 +265,9 @@ class ThreadIndexMode < LineCursorMode
def load_n_threads_background n=LOAD_MORE_THREAD_NUM, opts={}
return if @load_thread
- @load_thread = ::Thread.new do
- begin
- num = load_n_threads n, opts
- opts[:when_done].call(num) if opts[:when_done]
- rescue Exception => e
- $exception ||= e
- raise
- end
+ @load_thread = Redwood::reporting_thread do
+ num = load_n_threads n, opts
+ opts[:when_done].call(num) if opts[:when_done]
@load_thread = nil
end
end
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
@@ -13,12 +13,10 @@ class PollManager
self.class.i_am_the_instance self
- ::Thread.new do
+ Redwood::reporting_thread do
while true
sleep DELAY / 2
- if @last_poll.nil? || (Time.now - @last_poll) >= DELAY
- poll
- end
+ poll if @last_poll.nil? || (Time.now - @last_poll) >= DELAY
end
end
end
@@ -46,6 +44,7 @@ class PollManager
found = {}
total_num = 0
total_numi = 0
+
Index.usual_sources.each do |source|
next if source.done?
yield "Loading from #{source}... "
@@ -60,7 +59,7 @@ class PollManager
m = Redwood::Message.new :source => source, :source_info => offset,
:labels => labels
if found[m.id]
- yield "Skipping duplicate message #{m.id} (source total #{source.total})"
+ yield "Skipping duplicate message #{m.id}"
next
else
found[m.id] = true
@@ -79,7 +78,7 @@ class PollManager
if num % 1000 == 0 && num > 0
elapsed = Time.now - start
pctdone = (offset.to_f - start_offset) / (source.total.to_f - start_offset)
- remaining = (source.total.to_f - offset.to_f) * (elapsed.to_f / (offset.to_f - start_offset))
+ remaining = (source.end_offset.to_f - offset.to_f) * (elapsed.to_f / (offset.to_f - start_offset))
yield "## #{num} (#{(pctdone * 100.0)}% done) read; #{elapsed.to_time_s} elapsed; est. #{remaining.to_time_s} remaining"
end
end