[Tkinter-discuss] thread module

Amit Finkler amit.finkler at gmail.com
Sun Apr 6 15:45:12 CEST 2008

Hi all,

mkieverpy at tlink.de wrote:

> Hi Amit,
>> 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.
> This sounds wrong. You don't need QuitThread as a parameter to
> start_new_thread.
Fixed that. No errors yet.
>> 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.
> has your problem been solved in the mean time?
> If not two things to check/try:
> - thread.exit works by throwing an exception. Make sure you don't
>   catch it by accident.
In my function (in the second module), the loops runs in a "try:" and I
added the following exception:

    except QuitThread == 1:  

Now, it crashes with the following error message

    NameError: global name 'QuitThread' is not defined

and it points to the above exception as the source of the error. This is
strange, since QuitThread is definitely defined as a global variable in
the main module.

> - Print/log value of QuitThread on every access in both threads.
By the way, it *doesn't* crash when I comment out the "print QuitThread"
line inside the loop.

Thanks for you help,

> Cheers,
> ------------------------------------------------------------------------------
> Matthias Kievernagel                                      Software development
> mkiever/at/web/dot/de                             http://mkiever.home.tlink.de
> ------------------------------------------------------------------------------
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss

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

More information about the Tkinter-discuss mailing list