Best way to kill a thread started from a TkButton push

Hello all,

Looking for the best way to kill a thread started from
a TkButton push.

I’m just using one thread that I would like to control
via a Tk Start button and a Tk Stop button.

The reason for the question is that I’m using a method
called stop_thread that takes the thread to stop as
it’s argument and simply using thread.kill, and
setting my button states back to normal ; This for the
most part works except when I call it from code as
opposed to from a user event. The button states do
not go back to normal for some reason when I call
stop_thread from code.

BTW it’s the tk8.3 lib on win32.

Thanks in advance,

Jason

Jason T. wrote:

it’s argument and simply using thread.kill, and
setting my button states back to normal ; This for the
most part works except when I call it from code as
opposed to from a user event. The button states do
not go back to normal for some reason when I call
stop_thread from code.

BTW it’s the tk8.3 lib on win32.

I can’t help with your problem exactly, but this sounds like it is to do
with the Binding of the variable(s).
See the Pickaxe book: http://www.rubycentral.com/book/ext_tk.html

An excerpt:
“One small caution when using the code block form: the scope of
variables is not what you think it is. The block is actually evaluated
in the context of the widget’s object, not the caller’s. …”

Regards,
JJ

John J. wrote:

Jason T. wrote:

it’s argument and simply using thread.kill, and
setting my button states back to normal ; This for the
most part works except when I call it from code as
opposed to from a user event. The button states do
not go back to normal for some reason when I call
stop_thread from code.

BTW it’s the tk8.3 lib on win32.

I can’t help with your problem exactly, but this sounds like it is to do
with the Binding of the variable(s).
See the Pickaxe book: http://www.rubycentral.com/book/ext_tk.html

An excerpt:
“One small caution when using the code block form: the scope of
variables is not what you think it is. The block is actually evaluated
in the context of the widget’s object, not the caller’s. …”

Regards,
JJ

Thanks, you got me thinking about the scope and it ended up being just
that, the scope awareness caution excerpt you provided from the pickaxe
book.

Regards,

Jason

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs