aboutsummaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorBarneyStratford <barney_stratford@fastmail.fm>2021-02-02 20:24:24 +0000
committerGitHub <noreply@github.com>2021-02-02 20:24:24 +0000
commit01c4fddc4b2ac707f226e0bd92679588d2252cc4 (patch)
treef0861e313364e198913b4c14c519f603c1618342 /Lib/test
parentbpo-42997: Improve error message for missing : before suites (GH-24292) (diff)
downloadcpython-01c4fddc4b2ac707f226e0bd92679588d2252cc4.tar.gz
cpython-01c4fddc4b2ac707f226e0bd92679588d2252cc4.tar.bz2
cpython-01c4fddc4b2ac707f226e0bd92679588d2252cc4.zip
bpo-41149: Fix a bug in threading that causes fals-y threads callables to fail to start. (GH-21201)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_threading.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 0a4372ec2df..a7a716ed59f 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -855,6 +855,26 @@ class ThreadTests(BaseTestCase):
""")
self.assertEqual(out.rstrip(), b"thread_dict.atexit = 'value'")
+ def test_boolean_target(self):
+ # bpo-41149: A thread that had a boolean value of False would not
+ # run, regardless of whether it was callable. The correct behaviour
+ # is for a thread to do nothing if its target is None, and to call
+ # the target otherwise.
+ class BooleanTarget(object):
+ def __init__(self):
+ self.ran = False
+ def __bool__(self):
+ return False
+ def __call__(self):
+ self.ran = True
+
+ target = BooleanTarget()
+ thread = threading.Thread(target=target)
+ thread.start()
+ thread.join()
+ self.assertTrue(target.ran)
+
+
class ThreadJoinOnShutdown(BaseTestCase):