From: Hidetoshi NAGAI Date: 2011-04-25T07:16:11+09:00 Subject: Re: Tk : non blocking Tk.mainloop Hi, I'm very sorry for my late response. From: Juju SL Subject: Tk : non blocking Tk.mainloop Date: Thu, 14 Apr 2011 02:20:37 +0900 Message-ID: <58d66ab4de539ec84adb59d9fbde9312@ruby-forum.com> > I did some canvas tests on my Debian Squeeze with Ruby 1.8 + Tk, and > everything was OK. > > Then I chose to move to Ruby 1.9 ; so I cleaned my old Ruby packages and > installed "ruby1.9.1-full package", which comes with Tk8.4 > > My problem is I can't get Ruby TK programs run properly, because the > Tk.mainloop is non blocking ; my program exists immediately, I only see > the Tk canvas appear and disappear. I don't use Debian. I couldn't re-generate your trouble on my environment. It may depend on race condition of native threads. Could you try the followings and report the results? (1) If you call Tk.mainloop on the main thread only, please call the follwing line berore "require 'tk'". ---------------------------------------------------------------------- module TkCore; RUN_EVENTLOOP_ON_MAIN_THREAD = true; end ---------------------------------------------------------------------- (2) Please run your simple script, which occurs your trouble, with -d option. e.g. ---------------------------------------------------------------------- ruby -d your_script.rb > exec.log 2>&1 ---------------------------------------------------------------------- If it has same trouble, please send me the log file. (3) Please apply the following patch. If it has same trouble, please send the log when running with -d option. =================================================== --- tk.rb-orig 2011-04-25 06:37:19.000000000 +0900 +++ tk.rb 2011-04-25 06:54:13.000000000 +0900 @@ -1271,6 +1271,7 @@ } set __initial_state_of_rubytk__ 1 trace add variable __initial_state_of_rubytk__ unset __startup_rbtk_mainloop__ +update EOS begin @@ -1301,7 +1302,8 @@ } until INTERP_THREAD[:interp] - Thread.pass + #Thread.pass + INTERP_THREAD.run end # INTERP_THREAD.run raise INTERP_THREAD[:interp] if INTERP_THREAD[:interp].kind_of? Exception =================================================== -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) Department of Artificial Intelligence, Kyushu Institute of Technology