Title: Threads can fail to start
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Barney Stratford, python-dev
Priority: normal Keywords: patch

Created on 2020-06-28 16:01 by Barney Stratford, last changed 2020-06-28 19:59 by python-dev.

Pull Requests
URL Status Linked Edit
PR 21201 open python-dev, 2020-06-28 19:59
Messages (1)
msg372521 - (view) Author: Barney Stratford (Barney Stratford) * Date: 2020-06-28 16:01
>>> 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 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.
Date User Action Args
2020-06-28 19:59:39python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request20356
stage: patch review
2020-06-28 16:01:04Barney Stratfordcreate