From: Hidetoshi NAGAI Date: 2011-05-02T18:51:40+09:00 Subject: Re: Tk : non blocking Tk.mainloop From: Hidetoshi NAGAI Subject: Re: Tk : non blocking Tk.mainloop Date: Sat, 30 Apr 2011 07:27:07 +0900 Message-ID: <20110430.072659.74734013.nagai@ai.kyutech.ac.jp> > I can focus to check when such race condition occurs. Could you try the followiing patch? --- ../ruby-1.9.2-p0.orig/ext/tk/lib/tk.rb 2010-06-29 06:44:06.000000000 +0900 +++ ext/tk/lib/tk.rb 2011-05-02 18:16:29.000000000 +0900 @@ -1236,6 +1236,9 @@ raise e end + interp.mainloop_abort_on_exception = true + Thread.current.instance_variable_set("@interp", interp) + status = [nil] def status.value self[0] @@ -1271,19 +1274,23 @@ } set __initial_state_of_rubytk__ 1 trace add variable __initial_state_of_rubytk__ unset __startup_rbtk_mainloop__ + +# complete initializing +ruby {TkCore::INTERP_THREAD[:interp] = TkCore::INTERP_THREAD.instance_variable_get('@interp')} EOS begin begin #TclTkLib.mainloop_abort_on_exception = false #Thread.current[:status].value = TclTkLib.mainloop(true) - interp.mainloop_abort_on_exception = true - Thread.current[:interp] = interp + #interp.mainloop_abort_on_exception = true + #Thread.current[:interp] = interp Thread.current[:status].value = interp.mainloop(true) rescue SystemExit=>e Thread.current[:status].value = e rescue Exception=>e Thread.current[:status].value = e + p e if $DEBUG retry if interp.has_mainwindow? ensure INTERP_MUTEX.synchronize{ INTERP_ROOT_CHECK.broadcast } @@ -1300,12 +1307,20 @@ end } + # check a Tcl/Tk interpreter is initialized 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 + # check an eventloop is running + while INTERP_THREAD.alive? && TclTkLib.mainloop_thread?.nil? + INTERP_THREAD.run + end + INTERP = INTERP_THREAD[:interp] INTERP_THREAD_STATUS = INTERP_THREAD[:status] @@ -1316,6 +1331,9 @@ INTERP_THREAD.kill end } + + # (for safety's sake) force the eventloop to run + INTERP_THREAD.run end def INTERP.__getip -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) Department of Artificial Intelligence, Kyushu Institute of Technology