Interesting Thread Gotcha

Dan thermostat at gmail.com
Wed Jan 16 13:07:59 EST 2008


On Jan 16, 11:06 am, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> Hendrik van Rooyen wrote:
> > "Dan" <the,,,ail.com> wrote:
>
> >> >>> keyboard_thread = thread.start_new_thread(kbd_driver (port_q,kbd_q))
>
> >> Needs to be
> >> >>> keyboard_thread = thread.start_new_thread(kbd_driver, (port_q,kbd_q))
>
> >> Commas are important!
>
> >> -Dan
>
> > Absolutely! - well spotted!
>
> > As the first correct respondent, you win the freedom to spend a week in
> > Naboomspruit at your own expense.
>
> > It would have been nice, however, to have gotten something like:
>
> > TypeError - This routine needs a tuple.
>
> > instead of the silent in line calling of the routine in question,
> > while failing actually to start a new thread.
>
> You can't prevent the silent inline-calling - otherwise, how would you do
> this:
>
> def compute_thread_target():
>     def target():
>         pass
>     return target
>
> thread.start_new_thread(compute_thread_target())
>
> Of course start_new_thread could throw an error if it got nothing callable
> as first argument. No idea why it doesn't.
>
> Diez

Of course, in his case, having start_new_thread throw an error
wouldn't have helped, since he went into an infinite loop while
evaluating the parameters for start_new_thread.

Would it be possible to have pychecker (or some such) warn that there
is an insufficient parameter count to start_new_thread? I guess that
would require knowing the type of thread. . .

-Dan



More information about the Python-list mailing list