List Info

Thread: Re: problem with Gauge on windows xp...




Re: problem with Gauge on windows xp...
country flaguser name
United Kingdom
2008-02-28 17:31:08
Tim Ferrell wrote:
> It ran fine for me on XP (thanks!) but for some reason
when running it 
> on my Mac it just freezes up as soon as it starts...
I'm on Leopard 
> (10.5.2) using MacPorts for ruby with the latest wxruby
gem... Any ideas 
> what might be happening??
I tried it on 10.5.2 with system ruby + 1.9.4 gem - after a
few runs, I 
see what you mean. I got this error message once.

2008-02-28 23:06:02.105 ruby[64018:10b] *** Exception
handlers were not 
properly removed. Some code has jumped or returned out of an

NS_DURING...NS_HANDLER region without using the
NS_VOIDRETURN or 
NS_VALUERETURN macros.

Which makes me think that the thread scheduler is jumping
out of some 
critical portion of GUI code. I reworked the example so that
all GUI 
updating is done through the main thread, using monitor to
check 
progress with thread-local variables. This seems to work
reliably now on 
OS X.

hth
alex

__
  def start_job(idx)
    Thread.abort_on_exception = true
    url = "blah #"
    fname = File.basename(url)
    dialog.status_label.label = "Faking download
# of #: #"
    dialog.update
    dialog.progress_all.value = (100 * (idx/10.0)).to_i

    worker = Thread.new do
      Thread.current[:progress] = 0
      1.upto(10) do | count |
        break if dialog.cancelled
        Thread.current[:progress] = (100 *
(count/10.0)).to_i
        sleep(0.1)
      end
      if dialog.cancelled
        Thread.stop
      end
    end
  end

  # Test the state of the queue and worker progress
  def monitor_jobs
    if not worker # Get started
      dialog.show
      start_job(job_n)
    elsif worker and job_n < 10 # Still running
      if dialog.cancelled # test for cancellation
        finish
      end
      if worker.status
        dialog.progress_item.value = worker[:progress]     
      else # start next
        start_job(job_n += 1)
      end
    else # completed
      finish
    end
  end




_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users

Thread code questions
country flaguser name
Germany
2008-02-29 01:56:00
Hi!

I followed the 'problem with Gauge on windows xp...'
discussion and I'm 
having difficulties to understand the resulting code from
Alex. As my 
problems are not connected to Tims problem, I start a new
one.

Please bear in mind that these are questions because I would
like to 
understand the code and are not meant as a critical comment
about the 
code. 

Am 28 Feb 2008 um 23:31 hat Alex Fenton geschrieben:
> 
>def start_job(idx)
>  Thread.abort_on_exception = true
>  url = "blah #"
>  fname = File.basename(url)
>  dialog.status_label.label = "Faking download
# of #: #" 

1. Is there any advantage of writing "#"
instead of "10" here, I 
don't see?

>  dialog.update
>  dialog.progress_all.value = (100 * (idx/10.0)).to_i
>  worker = Thread.new do
>    Thread.current[:progress] = 0

2. Is Thread.current not identical with self inside the
block?
3. Why do we have to define the thread-local progress here?
Without 
this line it would also be defined as a thread-local
variable in the 
upto-block, wouldn't be a block variable and would so
survive the block 
cycles, wouldn't it?

>    1.upto(10) do | count |
>      break if dialog.cancelled
>      Thread.current[:progress] = (100 *
(count/10.0)).to_i

4. Why is the former dialog.update now unnecessary?

>      sleep(0.1)
>    end
>    if dialog.cancelled
>      Thread.stop
>    end

5. Why not directely 'Thread.stop if dialog.cancelled' in the
upto-
block? finish exits in this case anyway. What am I
overlooking?

>  end
>end


Am 28 Feb 2008 um 21:15 hat Alex Fenton geschrieben:

> def finish
>   monitor.stop
>   if dialog.cancelled
>     dialog.hide
>     md = Wx::MessageDialog.new(dialog, "You
cancelled!", 
>                                 TITLE, 
>                                
Wx::OK|Wx::ICON_EXCLAMATION)
>     md.show_modal
>     code = 1                        
>   else
>     dialog.progress_all.value = 100
>     dialog.hide
>     md = Wx::MessageDialog.new(dialog, 'Fake download(s)
complete!', 
>                                TITLE, Wx::OK, Wx:EFAULT_P
OSITION)
>     md.show_modal                        
>     dialog.hide

6. Why do we need 'dialog.hide' two times?

>     code = 0  
>   end  
>   dialog.destroy
>   exit(code)
> end


Thanks in advance if someone is willing to help me
understand.
Dirk
_______________________________________________
wxruby-users mailing list
wxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/wxruby-users

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )