Ruby 1.9.1 + Tk problem

Discussion in 'Ruby' started by Diego Virasoro, Apr 6, 2009.

  1. Hello,
    I have a Ruby/Tk code that runs perfectly in 1.8.x but stalls in
    1.9.1.

    Doing some investigation it seems that even the very basic programs:
    require 'tk'

    (that's not a mistake... it's literally only the require line) ends up
    freezing the program. Anyone has any idea on what could be the
    problem?

    I am running Mac Os X 10.4 (Tiger), on a G4 machine.

    Thank you

    Diego
     
    Diego Virasoro, Apr 6, 2009
    #1
    1. Advertising

  2. From: Diego Virasoro <>
    Subject: Ruby 1.9.1 + Tk problem
    Date: Mon, 6 Apr 2009 19:34:21 +0900
    Message-ID: <>
    > I have a Ruby/Tk code that runs perfectly in 1.8.x but stalls in
    > 1.9.1.
    >
    > Doing some investigation it seems that even the very basic programs:
    > require 'tk'
    >
    > (that's not a mistake... it's literally only the require line) ends up
    > freezing the program. Anyone has any idea on what could be the
    > problem?
    >
    > I am running Mac Os X 10.4 (Tiger), on a G4 machine.


    I'm very sorry, but I cannot check troubles on Mac OSX.
    I need main information (trial and error) to fix troubles.

    First of all, does the following work fine?
    ---------------------------------------------------------------------
    require 'tcltklib'
    ip = TclTkIp.new
    ip._invoke('button', '.b', '-text', 'TEST', '-command', 'puts OK')
    ip._invoke('pack', '.b')
    TclTkLib.mainloop
    ---------------------------------------------------------------------
    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Apr 6, 2009
    #2
    1. Advertising

  3. tested on linux (ruby 1.9.1, tk8.5.3, tcl8.5.3)

    successful compilation..

    but, the script you've suggested

    require 'tcltklib'
    ip =3D TclTkIp.new
    ip._invoke('button', '.b', '-text', 'TEST', '-command', 'puts OK')
    ip._invoke('pack', '.b')
    TclTkLib.mainloop

    generated the following error.

    ruby test.rb
    test.rb:1:in `require': no such file to load -- tcltklib (LoadError)
    from test.rb:1:in `<main>'

    is this different problems?

    2009. 04. 07, =BF=C0=C0=FC 6:51, Hidetoshi NAGAI =C0=DB=BC=BA:

    > From: Diego Virasoro <>
    > Subject: Ruby 1.9.1 + Tk problem
    > Date: Mon, 6 Apr 2009 19:34:21 +0900
    > Message-ID: =

    <=20
    > >
    >> I have a Ruby/Tk code that runs perfectly in 1.8.x but stalls in
    >> 1.9.1.
    >>
    >> Doing some investigation it seems that even the very basic programs:
    >> require 'tk'
    >>
    >> (that's not a mistake... it's literally only the require line) ends =20=


    >> up
    >> freezing the program. Anyone has any idea on what could be the
    >> problem?
    >>
    >> I am running Mac Os X 10.4 (Tiger), on a G4 machine.

    >
    > I'm very sorry, but I cannot check troubles on Mac OSX.
    > I need main information (trial and error) to fix troubles.
    >
    > First of all, does the following work fine?
    > ---------------------------------------------------------------------
    > require 'tcltklib'
    > ip =3D TclTkIp.new
    > ip._invoke('button', '.b', '-text', 'TEST', '-command', 'puts OK')
    > ip._invoke('pack', '.b')
    > TclTkLib.mainloop
    > ---------------------------------------------------------------------
    > --=20
    > Hidetoshi NAGAI ()
    >
    >
     
    Jun Young Kim, Apr 7, 2009
    #3
  4. From: Jun Young Kim <>
    Subject: Re: Ruby 1.9.1 + Tk problem
    Date: Tue, 7 Apr 2009 11:12:15 +0900
    Message-ID: <>
    > generated the following error.
    >
    > ruby test.rb
    > test.rb:1:in `require': no such file to load -- tcltklib (LoadError)
    > from test.rb:1:in `<main>'
    >
    > is this different problems?


    Yes.
    Probably, ext/tk/extconf.rb failed to find Tcl/Tk headers or libraries.
    So, extconf.rb made an invalid Makefile, and tcltklib.c wasn't compiled.
    Please read ext/tk/README.tcltklib and re-generate a proper Makefile.
    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Apr 7, 2009
    #4
  5. Diego Virasoro

    Guest

    > I'm very sorry, but I cannot check troubles on Mac OSX.
    > I need main information (trial and error) to fix troubles.


    Thanks for the effort then. :)

    > First of all, does the following work fine?

    Yep. It does.

    Tell me what to test next. :)

    Diego
     
    , Apr 8, 2009
    #5
  6. From:
    Subject: Re: Ruby 1.9.1 + Tk problem
    Date: Wed, 8 Apr 2009 23:45:08 +0900
    Message-ID: <>
    > > First of all, does the following work fine?

    > Yep. It does.
    >
    > Tell me what to test next. :)


    Well, could you try the following patch?

    --- tk.rb.orig 2009-04-07 06:04:22.000000000 +0900
    +++ tk.rb 2009-04-09 06:27:07.000000000 +0900
    @@ -1130,30 +1130,30 @@
    opts = ''
    end

    - if WITH_RUBY_VM ### check Ruby 1.9 !!!!!!!
    - # *** NEED TO FIX ***
    - ip = TclTkIp.new(name, opts)
    - if ip._invoke_without_enc('tk', 'windowingsystem') == 'aqua' &&
    - (TclTkLib.get_version <=> [8,4,TclTkLib::RELEASE_TYPE::FINAL,9]) > 0
    - # *** KNOWN BUG ***
    - # Main event loop thread of TkAqua (> Tk8.4.9) must be the main
    - # application thread. So, ruby1.9 users must call Tk.mainloop on
    - # the main application thread.
    - RUN_EVENTLOOP_ON_MAIN_THREAD = true
    - INTERP = ip
    - else
    - unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
    - RUN_EVENTLOOP_ON_MAIN_THREAD = false
    - end
    - if RUN_EVENTLOOP_ON_MAIN_THREAD
    + unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
    + if WITH_RUBY_VM ### check Ruby 1.9 !!!!!!!
    + # *** NEED TO FIX ***
    + ip = TclTkIp.new(name, opts)
    + if ip._invoke_without_enc('tk', 'windowingsystem') == 'aqua' &&
    + (TclTkLib.get_version<=>[8,4,TclTkLib::RELEASE_TYPE::FINAL,9]) > 0
    + # *** KNOWN BUG ***
    + # Main event loop thread of TkAqua (> Tk8.4.9) must be the main
    + # application thread. So, ruby1.9 users must call Tk.mainloop on
    + # the main application thread.
    + RUN_EVENTLOOP_ON_MAIN_THREAD = true
    INTERP = ip
    else
    - ip.delete
    + unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
    + RUN_EVENTLOOP_ON_MAIN_THREAD = false
    + end
    + if RUN_EVENTLOOP_ON_MAIN_THREAD
    + INTERP = ip
    + else
    + ip.delete
    + end
    end
    - end
    - ip = nil
    - else
    - unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
    + ip = nil
    + else
    RUN_EVENTLOOP_ON_MAIN_THREAD = false
    end
    end
    @@ -1202,6 +1202,9 @@
    INTERP_THREAD_STATUS = INTERP_THREAD[:status]
    end

    + # WINDOWING_SYSTEM = TclTkLib::WINDOWING_SYSTEM
    + WINDOWING_SYSTEM = INTERP._invoke_without_enc('tk', 'windowingsystem')
    +
    def INTERP.__getip
    self
    end
    @@ -1703,12 +1706,15 @@
    TclTkLib.mainloop(check_root)

    elsif TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    - # if TclTkLib::WINDOWING_SYSTEM == 'aqua' &&
    - if TkCore::INTERP._invoke_without_enc('tk','windowingsystem')=='aqua' &&
    - Thread.current != Thread.main &&
    - (TclTkLib.get_version <=> [8,4,TclTkLib::RELEASE_TYPE::FINAL,9]) > 0
    - raise RuntimeError,
    - "eventloop on TkAqua ( > Tk8.4.9 ) works on the main thread only"
    + if Thread.current != Thread.main
    + msg = 'eventloop on '
    + if TkCore::WINDOWING_SYSTEM == 'aqua' &&
    + (TclTkLib.get_version<=>[8,4,TclTkLib::RELEASE_TYPE::FINAL,9]) > 0
    + msg << "TkAqua ( > Tk8.4.9 )"
    + else
    + msg << "your current environment (or setting)"
    + end
    + raise RuntimeError, msg << " works on the main thread only"
    end
    TclTkLib.mainloop(check_root)


    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Apr 8, 2009
    #6
  7. Diego Virasoro

    Guest

    I'll try as soon as I can (though I am a bit busy right now).

    However I tried to read a bit of the tk.rb file... and noticed the
    known bug about TkAqua. My Tk is version 8.4.7... could it be that
    that too has the same bug? (you check for a version >8.4.9).

    Thanks again.

    Diego
     
    , Apr 9, 2009
    #7
  8. From:
    Subject: Re: Ruby 1.9.1 + Tk problem
    Date: Thu, 9 Apr 2009 22:25:04 +0900
    Message-ID: <>
    > However I tried to read a bit of the tk.rb file... and noticed the
    > known bug about TkAqua. My Tk is version 8.4.7... could it be that
    > that too has the same bug? (you check for a version >8.4.9).


    May not be...
    I thought that such kind of trouble depends on TkAqua's specification
    with native threads.
    If you use standard Tcl/Tk.framework libraries and you have no other
    Tcl/Tk libraries on your MacOSX box, please tell me your configure
    options when you compiled ruby (tcltklib).

    However, I'm happy if you try the patch and report the result of the
    following two test codes which are different at the first line only.
    ---------------------------------------------------------------
    module TkCore; RUN_EVENTLOOP_ON_MAIN_THREAD=false; end
    p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    require 'tk'
    p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    p TkButton.new:)text=>'TEST',:command=>proc{p 'test'}).pack
    Tk.mainloop
    ---------------------------------------------------------------
    ---------------------------------------------------------------
    module TkCore; RUN_EVENTLOOP_ON_MAIN_THREAD=true; end
    p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    require 'tk'
    p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    p TkButton.new:)text=>'TEST',:command=>proc{p 'test'}).pack
    Tk.mainloop
    ---------------------------------------------------------------
    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Apr 9, 2009
    #8
  9. this is a first example.
    $> ruby test.rb
    false
    false
    #<Tk::Button:0x000000012257a8 @path=3D".w00000">
    "test" <-- when I click "TEST" button.
    "test"
    "test"

    this is a second example.
    $> ruby test.rb
    true
    true
    #<Tk::Button:0x00000000be2918 @path=3D".w00000">
    "test" <-- when I click "TEST" button.
    "test"

    2009. 04. 10, =BF=C0=C0=FC 6:22, Hidetoshi NAGAI =C0=DB=BC=BA:

    > From:
    > Subject: Re: Ruby 1.9.1 + Tk problem
    > Date: Thu, 9 Apr 2009 22:25:04 +0900
    > Message-ID: =

    <=20
    > >
    >> However I tried to read a bit of the tk.rb file... and noticed the
    >> known bug about TkAqua. My Tk is version 8.4.7... could it be that
    >> that too has the same bug? (you check for a version >8.4.9).

    >
    > May not be...
    > I thought that such kind of trouble depends on TkAqua's specification
    > with native threads.
    > If you use standard Tcl/Tk.framework libraries and you have no other
    > Tcl/Tk libraries on your MacOSX box, please tell me your configure
    > options when you compiled ruby (tcltklib).
    >
    > However, I'm happy if you try the patch and report the result of the
    > following two test codes which are different at the first line only.
    > ---------------------------------------------------------------
    > module TkCore; RUN_EVENTLOOP_ON_MAIN_THREAD=3Dfalse; end
    > p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    > require 'tk'
    > p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    > p TkButton.new:)text=3D>'TEST',:command=3D>proc{p 'test'}).pack
    > Tk.mainloop
    > ---------------------------------------------------------------
    > ---------------------------------------------------------------
    > module TkCore; RUN_EVENTLOOP_ON_MAIN_THREAD=3Dtrue; end
    > p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    > require 'tk'
    > p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    > p TkButton.new:)text=3D>'TEST',:command=3D>proc{p 'test'}).pack
    > Tk.mainloop
    > ---------------------------------------------------------------
    > --=20
    > Hidetoshi NAGAI ()
    >
    >
     
    Jun Young Kim, Apr 14, 2009
    #9
  10. From: Jun Young Kim <>
    Subject: Re: Ruby 1.9.1 + Tk problem
    Date: Tue, 14 Apr 2009 16:37:26 +0900
    Message-ID: <>
    > this is a first example.

    (snip)
    > this is a second example.


    Thank you for your report.

    Probably, your test environment is

    > tested on linux (ruby 1.9.1, tk8.5.3, tcl8.5.3)


    (based on [ruby-talk: 333180]).

    I think that the trouble doesn't occur on linux.
    I reconfirmed that by your report.
    Thank you, again.

    But now, we investigate the trouble on MacOS X
    (or Diego's environment ;-)).
    I have no MacOS X environment.
    So, I need many information or advices to fix the problem.
    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Apr 16, 2009
    #10
  11. Diego Virasoro

    Guest

    On Apr 9, 10:22 pm, Hidetoshi NAGAI <> wrote:
    > From:
    > Subject: Re:Ruby1.9.1+Tkproblem
    > Date: Thu, 9 Apr 2009 22:25:04 +0900
    > Message-ID: <>
    >
    > > However I tried to read a bit of thetk.rb file... and noticed the
    > > known bug about TkAqua. MyTkis version 8.4.7... could it be that
    > > that too has the same bug? (you check for a version >8.4.9).

    >
    > May not be...
    > I thought that such kind of trouble depends on TkAqua's specification
    > with native threads.
    > If you use standard Tcl/Tk.framework libraries and you have no other
    > Tcl/Tklibraries on your MacOSX box, please tell me your configure
    > options when you compiledruby(tcltklib).
    >
    > However, I'm happy if you try the patch and report the result of the
    > following two test codes which are different at the first line only.
    > ---------------------------------------------------------------
    > module TkCore; RUN_EVENTLOOP_ON_MAIN_THREAD=false; end
    > p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    > require 'tk'
    > p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    > p TkButton.new:)text=>'TEST',:command=>proc{p 'test'}).packTk.mainloop
    > ---------------------------------------------------------------
    > ---------------------------------------------------------------
    > module TkCore; RUN_EVENTLOOP_ON_MAIN_THREAD=true; end
    > p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    > require 'tk'
    > p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
    > p TkButton.new:)text=>'TEST',:command=>proc{p 'test'}).packTk.mainloop
    > ---------------------------------------------------------------
    > --


    Hi, sorry for the delay.
    I've done everything you asked and here are the results.

    After applying the patch you sent, the first example stalls like
    usual, but the second one does not and it works perfectly well.

    So I tried without the patch, and I got the same results: the first
    case stalls, the second one works.

    Finally I tried adding that one line to my code, and indeed now it
    works perfectly well.

    My environment is OS X 10.4.11, Ruby 1.9.1p0, Tk 8.4.7. And my
    computer uses the old PowerPC CPU (a G4 to be exact).

    Thanks a lot for the help
     
    , Apr 21, 2009
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    220
  2. anne001
    Replies:
    1
    Views:
    483
  3. Phrogz
    Replies:
    4
    Views:
    233
    Austin Ziegler
    Sep 6, 2006
  4. roschler
    Replies:
    0
    Views:
    183
    roschler
    Oct 16, 2006
  5. Nicholas
    Replies:
    3
    Views:
    388
    Ryan Davis
    Jan 28, 2007
Loading...

Share This Page