[New-bugs-announce] [issue41149] Threads can fail to start

Barney Stratford report at bugs.python.org
Sun Jun 28 12:01:04 EDT 2020

New submission from Barney Stratford <barney_stratford at fastmail.fm>:

>>> import threading
>>> class foo (object):
...     def __bool__ (self):
...         return False
...     def __call__ (self):
...         print ("Running")
>>> threading.Thread (target = foo ()).start ()

The expected result of these commands would be for the thread to print
"Running". However, in actual fact it prints nothing at all. This is
because threading.Thread.run only runs the target if it is True as a
boolean. This is presumably to make the thread do nothing at all if
the target is None. In this case, I have a legitimate target that is
False as a boolean.

I propose to remove the test altogether. The effect of this is that
failure to set the target of the thread, or setting a non-callable
target, will cause the thread to raise a TypeError as soon as it is
started. Forgetting to set the target is in almost every case a bug,
and bugs should never be silent.

PR to follow.

components: Library (Lib)
messages: 372521
nosy: BarneyStratford
priority: normal
severity: normal
status: open
title: Threads can fail to start
type: behavior
versions: Python 3.10

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list