[Tkinter-discuss] thread module

Amit Finkler amit.finkler at gmail.com
Wed Apr 2 09:58:22 CEST 2008

Tim Jones wrote:

> On Apr 1, 2008, at 6:05 AM, Amit Finkler wrote:
>> Hi,
>> Following a previous post of mine (http://mail.python.org/pipermail/ 
>> tkinter-discuss/2008-March/001320.html), I finally managed to start  
>> a new thread using the thread module. This new thread is started by  
>> clicking on a button on my Tkinter GUI and it just continuously  
>> plots a graph using matplotlib.
>> Now, however, a new problem arises - how does one close the  
>> thread??? The function this thread starts has a Ctrl-C Exception  
>> which works fine if the thread module is not used. Now, however,  
>> pressing Ctrl-C does nothing. The thread has a life of its own!!!
>> Your help will be greatly appreciated.
> The simplest solution is to set a global flag "QuitThread" and set it  
> to False while running.  Then, allow the user to click a button and  
> then set the value to True.  In the thread, check the value of the  
> variable and exit if it's True.
> HTH,
> Tim
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
I may have messed up a bit the entire point of global variables, but
here goes:

1.   I created a global variable named "QuitThread" on my main module.
2.   I initially set it to "False".
3.   When clicking on the "Run" button of my GUI (defined in the main
module), a new thread starts using start_new_thread, where QuitThread is
one of the variables in its tuple.
4.   This new thread runs a function from a second module. In this
module I also added "import thread".
5.   This function runs a loop in which it checks every iteration
whether QuitThread is True or False.
6.   If it is True, it executes "thread.exit()".
7.   Nothing happens. The thread continues on running.

Hope there is enough information for you to be able to help me :-)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20080402/0514ad21/attachment.htm 

More information about the Tkinter-discuss mailing list