Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_threading.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 6e2089dbc5ad |
| children |
| rev | line source |
|---|---|
|
85492
764ceb41192b
test_threading isn't rudimentary anymore
Antoine Pitrou <solipsis@pitrou.net>
parents:
85463
diff
changeset
|
1 """ |
|
764ceb41192b
test_threading isn't rudimentary anymore
Antoine Pitrou <solipsis@pitrou.net>
parents:
85463
diff
changeset
|
2 Tests for the threading module. |
|
764ceb41192b
test_threading isn't rudimentary anymore
Antoine Pitrou <solipsis@pitrou.net>
parents:
85463
diff
changeset
|
3 """ |
|
19405
9de83dda9f09
add a few test cases for threading module.
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
4 |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46304
diff
changeset
|
5 import test.support |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
6 from test.support import verbose, strip_python_stderr, import_module |
|
76421
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
7 from test.script_helper import assert_python_ok |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
8 |
|
19405
9de83dda9f09
add a few test cases for threading module.
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
9 import random |
|
47555
7d824fd131ad
Merged revisions 63829-63831,63858,63865,63879,63882,63948,63970-63972,63976,63989,64014-64015,64021-64022,64063-64065,64067 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47266
diff
changeset
|
10 import re |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
11 import sys |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
12 _thread = import_module('_thread') |
|
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
13 threading = import_module('threading') |
|
85398
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
14 import _testcapi |
|
19405
9de83dda9f09
add a few test cases for threading module.
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
15 import time |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
16 import unittest |
|
45495
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
17 import weakref |
|
55402
df5a70860781
Use unittest.SkipTest to skip tests in test_threading.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55401
diff
changeset
|
18 import os |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
19 from test.script_helper import assert_python_ok, assert_python_failure |
|
67340
ad2f34380aac
Merged revisions 87710 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
66340
diff
changeset
|
20 import subprocess |
|
19405
9de83dda9f09
add a few test cases for threading module.
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
21 |
|
57160
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
22 from test import lock_tests |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
23 |
|
85520
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
24 |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
25 # Between fork() and exec(), only async-safe functions are allowed (issues |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
26 # #12316 and #11870), and fork() from a worker thread is known to trigger |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
27 # problems with some operating systems (issue #3863): skip problematic tests |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
28 # on platforms known to behave badly. |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
29 platforms_to_skip = ('freebsd4', 'freebsd5', 'freebsd6', 'netbsd5', |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
30 'hp-ux11') |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
31 |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
32 |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
33 # A trivial mutable counter. |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
34 class Counter(object): |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
35 def __init__(self): |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
36 self.value = 0 |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
37 def inc(self): |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
38 self.value += 1 |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
39 def dec(self): |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
40 self.value -= 1 |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
41 def get(self): |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
42 return self.value |
|
19405
9de83dda9f09
add a few test cases for threading module.
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
43 |
|
9de83dda9f09
add a few test cases for threading module.
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
44 class TestThread(threading.Thread): |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
45 def __init__(self, name, testcase, sema, mutex, nrunning): |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
46 threading.Thread.__init__(self, name=name) |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
47 self.testcase = testcase |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
48 self.sema = sema |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
49 self.mutex = mutex |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
50 self.nrunning = nrunning |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
51 |
|
19405
9de83dda9f09
add a few test cases for threading module.
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
52 def run(self): |
|
45996
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
53 delay = random.random() / 10000.0 |
|
19405
9de83dda9f09
add a few test cases for threading module.
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
54 if verbose: |
|
46188
46348de63f61
Update test_threading with a couple changes from trunk that got lost due, I
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
46161
diff
changeset
|
55 print('task %s will run for %.1f usec' % |
|
48745
2614d501de9a
change is_daemon, set_daemon, get_name, and set_name to properties
Benjamin Peterson <benjamin@python.org>
parents:
48743
diff
changeset
|
56 (self.name, delay * 1e6)) |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
57 |
|
45996
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
58 with self.sema: |
|
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
59 with self.mutex: |
|
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
60 self.nrunning.inc() |
|
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
61 if verbose: |
|
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
62 print(self.nrunning.get(), 'tasks are running') |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52892
diff
changeset
|
63 self.testcase.assertTrue(self.nrunning.get() <= 3) |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
64 |
|
45996
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
65 time.sleep(delay) |
|
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
66 if verbose: |
|
48745
2614d501de9a
change is_daemon, set_daemon, get_name, and set_name to properties
Benjamin Peterson <benjamin@python.org>
parents:
48743
diff
changeset
|
67 print('task', self.name, 'done') |
|
47615
045f83a1b864
Merged revisions 64125 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47555
diff
changeset
|
68 |
|
45996
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
69 with self.mutex: |
|
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
70 self.nrunning.dec() |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52892
diff
changeset
|
71 self.testcase.assertTrue(self.nrunning.get() >= 0) |
|
45996
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
72 if verbose: |
|
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
73 print('%s is finished. %d tasks are running' % |
|
48745
2614d501de9a
change is_daemon, set_daemon, get_name, and set_name to properties
Benjamin Peterson <benjamin@python.org>
parents:
48743
diff
changeset
|
74 (self.name, self.nrunning.get())) |
|
47615
045f83a1b864
Merged revisions 64125 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47555
diff
changeset
|
75 |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
76 |
|
56883
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
77 class BaseTestCase(unittest.TestCase): |
|
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
78 def setUp(self): |
|
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
79 self._threads = test.support.threading_setup() |
|
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
80 |
|
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
81 def tearDown(self): |
|
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
82 test.support.threading_cleanup(*self._threads) |
|
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
83 test.support.reap_children() |
|
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
84 |
|
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
85 |
|
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
86 class ThreadTests(BaseTestCase): |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
87 |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
88 # Create a bunch of threads, let each do some work, wait until all are |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
89 # done. |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
90 def test_various_ops(self): |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
91 # This takes about n/3 seconds to run (about n/3 clumps of tasks, |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
92 # times about 1 second per clump). |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
93 NUMTASKS = 10 |
|
19405
9de83dda9f09
add a few test cases for threading module.
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
94 |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
95 # no more than 3 of the 10 can run at once |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
96 sema = threading.BoundedSemaphore(value=3) |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
97 mutex = threading.RLock() |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
98 numrunning = Counter() |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
99 |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
100 threads = [] |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
101 |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
102 for i in range(NUMTASKS): |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
103 t = TestThread("<thread %d>"%i, self, sema, mutex, numrunning) |
|
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
104 threads.append(t) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52892
diff
changeset
|
105 self.assertEqual(t.ident, None) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52892
diff
changeset
|
106 self.assertTrue(re.match('<TestThread\(.*, initial\)>', repr(t))) |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
107 t.start() |
|
19405
9de83dda9f09
add a few test cases for threading module.
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
108 |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
109 if verbose: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
110 print('waiting for all tasks to complete') |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
111 for t in threads: |
|
85623
74dc664ad699
Issue #18808 again: fix the after-fork logic for not-yet-started or already-stopped threads.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85598
diff
changeset
|
112 t.join() |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52892
diff
changeset
|
113 self.assertTrue(not t.is_alive()) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52892
diff
changeset
|
114 self.assertNotEqual(t.ident, 0) |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
115 self.assertFalse(t.ident is None) |
|
63167
764ec9bbf013
Add more tests for the threading.Thread.repr.
Brett Cannon <bcannon@gmail.com>
parents:
61073
diff
changeset
|
116 self.assertTrue(re.match('<TestThread\(.*, stopped -?\d+\)>', |
|
764ec9bbf013
Add more tests for the threading.Thread.repr.
Brett Cannon <bcannon@gmail.com>
parents:
61073
diff
changeset
|
117 repr(t))) |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
118 if verbose: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
119 print('all tasks done') |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
120 self.assertEqual(numrunning.get(), 0) |
|
19405
9de83dda9f09
add a few test cases for threading module.
Skip Montanaro <skip@pobox.com>
parents:
diff
changeset
|
121 |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
122 def test_ident_of_no_threading_threads(self): |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
123 # The ident still must work for the main thread and dummy threads. |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
124 self.assertFalse(threading.currentThread().ident is None) |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
125 def f(): |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
126 ident.append(threading.currentThread().ident) |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
127 done.set() |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
128 done = threading.Event() |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
129 ident = [] |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
130 _thread.start_new_thread(f, ()) |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
131 done.wait() |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
132 self.assertFalse(ident[0] is None) |
|
57141
381a62f1e635
Merged revisions 76149 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56744
diff
changeset
|
133 # Kill the "immortal" _DummyThread |
|
381a62f1e635
Merged revisions 76149 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56744
diff
changeset
|
134 del threading._active[ident[0]] |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
135 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
136 # run with a small(ish) thread stack size (256kB) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
137 def test_various_ops_small_stack(self): |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
138 if verbose: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
139 print('with 256kB thread stack size...') |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
140 try: |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
141 threading.stack_size(262144) |
|
47266
7fe3a8648ce2
Rename thread to _thread and dummy_thread to _dummy_thread. Issue #2875.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
142 except _thread.error: |
|
55402
df5a70860781
Use unittest.SkipTest to skip tests in test_threading.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55401
diff
changeset
|
143 raise unittest.SkipTest( |
|
df5a70860781
Use unittest.SkipTest to skip tests in test_threading.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55401
diff
changeset
|
144 'platform does not support changing thread stack size') |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
145 self.test_various_ops() |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
146 threading.stack_size(0) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
147 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
148 # run with a large thread stack size (1MB) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
149 def test_various_ops_large_stack(self): |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
150 if verbose: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
151 print('with 1MB thread stack size...') |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
152 try: |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
153 threading.stack_size(0x100000) |
|
47266
7fe3a8648ce2
Rename thread to _thread and dummy_thread to _dummy_thread. Issue #2875.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
154 except _thread.error: |
|
55402
df5a70860781
Use unittest.SkipTest to skip tests in test_threading.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55401
diff
changeset
|
155 raise unittest.SkipTest( |
|
df5a70860781
Use unittest.SkipTest to skip tests in test_threading.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55401
diff
changeset
|
156 'platform does not support changing thread stack size') |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
157 self.test_various_ops() |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
158 threading.stack_size(0) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
34363
diff
changeset
|
159 |
|
34363
35f31790c6f9
threading._DummyThread.__init__(): document obscure new code.
Tim Peters <tim.peters@gmail.com>
parents:
34362
diff
changeset
|
160 def test_foreign_thread(self): |
|
35f31790c6f9
threading._DummyThread.__init__(): document obscure new code.
Tim Peters <tim.peters@gmail.com>
parents:
34362
diff
changeset
|
161 # Check that a "foreign" thread can use the threading module. |
|
35f31790c6f9
threading._DummyThread.__init__(): document obscure new code.
Tim Peters <tim.peters@gmail.com>
parents:
34362
diff
changeset
|
162 def f(mutex): |
|
57160
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
163 # Calling current_thread() forces an entry for the foreign |
|
34363
35f31790c6f9
threading._DummyThread.__init__(): document obscure new code.
Tim Peters <tim.peters@gmail.com>
parents:
34362
diff
changeset
|
164 # thread to get made in the threading._active map. |
|
57160
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
165 threading.current_thread() |
|
34363
35f31790c6f9
threading._DummyThread.__init__(): document obscure new code.
Tim Peters <tim.peters@gmail.com>
parents:
34362
diff
changeset
|
166 mutex.release() |
|
35f31790c6f9
threading._DummyThread.__init__(): document obscure new code.
Tim Peters <tim.peters@gmail.com>
parents:
34362
diff
changeset
|
167 |
|
35f31790c6f9
threading._DummyThread.__init__(): document obscure new code.
Tim Peters <tim.peters@gmail.com>
parents:
34362
diff
changeset
|
168 mutex = threading.Lock() |
|
35f31790c6f9
threading._DummyThread.__init__(): document obscure new code.
Tim Peters <tim.peters@gmail.com>
parents:
34362
diff
changeset
|
169 mutex.acquire() |
|
47266
7fe3a8648ce2
Rename thread to _thread and dummy_thread to _dummy_thread. Issue #2875.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
170 tid = _thread.start_new_thread(f, (mutex,)) |
|
34363
35f31790c6f9
threading._DummyThread.__init__(): document obscure new code.
Tim Peters <tim.peters@gmail.com>
parents:
34362
diff
changeset
|
171 # Wait for the thread to finish. |
|
35f31790c6f9
threading._DummyThread.__init__(): document obscure new code.
Tim Peters <tim.peters@gmail.com>
parents:
34362
diff
changeset
|
172 mutex.acquire() |
|
58415
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
57218
diff
changeset
|
173 self.assertIn(tid, threading._active) |
|
58473
71acd4482e65
Merged revisions 77727 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58456
diff
changeset
|
174 self.assertIsInstance(threading._active[tid], threading._DummyThread) |
|
34363
35f31790c6f9
threading._DummyThread.__init__(): document obscure new code.
Tim Peters <tim.peters@gmail.com>
parents:
34362
diff
changeset
|
175 del threading._active[tid] |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
176 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
177 # PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
178 # exposed at the Python level. This test relies on ctypes to get at it. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
179 def test_PyThreadState_SetAsyncExc(self): |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
180 ctypes = import_module("ctypes") |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
181 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
182 set_async_exc = ctypes.pythonapi.PyThreadState_SetAsyncExc |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
183 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
184 class AsyncExc(Exception): |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
185 pass |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
186 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
187 exception = ctypes.py_object(AsyncExc) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
188 |
|
56599
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
189 # First check it works when setting the exception from the same thread. |
|
70530
5548197d1f22
Close #12028: Make threading._get_ident() public, rename it to
Victor Stinner <victor.stinner@haypocalc.com>
parents:
70450
diff
changeset
|
190 tid = threading.get_ident() |
|
56599
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
191 |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
192 try: |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
193 result = set_async_exc(ctypes.c_long(tid), exception) |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
194 # The exception is async, so we might have to keep the VM busy until |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
195 # it notices. |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
196 while True: |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
197 pass |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
198 except AsyncExc: |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
199 pass |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
200 else: |
|
57209
b354c1b6b476
Merged revisions 75149,75260-75263,75265-75267,75292,75300,75376,75405,75429-75433,75437,75445,75501,75551,75572,75589-75591,75657,75742,75868,75952-75957,76057,76105,76139,76143,76162,76223 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
57172
diff
changeset
|
201 # This code is unreachable but it reflects the intent. If we wanted |
|
b354c1b6b476
Merged revisions 75149,75260-75263,75265-75267,75292,75300,75376,75405,75429-75433,75437,75445,75501,75551,75572,75589-75591,75657,75742,75868,75952-75957,76057,76105,76139,76143,76162,76223 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
57172
diff
changeset
|
202 # to be smarter the above loop wouldn't be infinite. |
|
56599
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
203 self.fail("AsyncExc not raised") |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
204 try: |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
205 self.assertEqual(result, 1) # one thread state modified |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
206 except UnboundLocalError: |
|
57209
b354c1b6b476
Merged revisions 75149,75260-75263,75265-75267,75292,75300,75376,75405,75429-75433,75437,75445,75501,75551,75572,75589-75591,75657,75742,75868,75952-75957,76057,76105,76139,76143,76162,76223 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
57172
diff
changeset
|
207 # The exception was raised too quickly for us to get the result. |
|
56599
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
208 pass |
|
386414b846eb
Merged revisions 75499 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55402
diff
changeset
|
209 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
210 # `worker_started` is set by the thread when it's inside a try/except |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
211 # block waiting to catch the asynchronously set AsyncExc exception. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
212 # `worker_saw_exception` is set by the thread upon catching that |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
213 # exception. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
214 worker_started = threading.Event() |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
215 worker_saw_exception = threading.Event() |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
216 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
217 class Worker(threading.Thread): |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
218 def run(self): |
|
70530
5548197d1f22
Close #12028: Make threading._get_ident() public, rename it to
Victor Stinner <victor.stinner@haypocalc.com>
parents:
70450
diff
changeset
|
219 self.id = threading.get_ident() |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
220 self.finished = False |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
221 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
222 try: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
223 while True: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
224 worker_started.set() |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
225 time.sleep(0.1) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
226 except AsyncExc: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
227 self.finished = True |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
228 worker_saw_exception.set() |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
229 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
230 t = Worker() |
|
48745
2614d501de9a
change is_daemon, set_daemon, get_name, and set_name to properties
Benjamin Peterson <benjamin@python.org>
parents:
48743
diff
changeset
|
231 t.daemon = True # so if this fails, we don't hang Python at shutdown |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
232 t.start() |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
233 if verbose: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
234 print(" started worker thread") |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
235 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
236 # Try a thread id that doesn't make sense. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
237 if verbose: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
238 print(" trying nonsensical thread id") |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
239 result = set_async_exc(ctypes.c_long(-1), exception) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
240 self.assertEqual(result, 0) # no thread states modified |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
241 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
242 # Now raise an exception in the worker thread. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
243 if verbose: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
244 print(" waiting for worker thread to get started") |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
245 ret = worker_started.wait() |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49533
diff
changeset
|
246 self.assertTrue(ret) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
247 if verbose: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
248 print(" verifying worker hasn't exited") |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52892
diff
changeset
|
249 self.assertTrue(not t.finished) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
250 if verbose: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
251 print(" attempting to raise asynch exception in worker") |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
252 result = set_async_exc(ctypes.c_long(t.id), exception) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
253 self.assertEqual(result, 1) # one thread state modified |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
254 if verbose: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
255 print(" waiting for worker to say it caught the exception") |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
256 worker_saw_exception.wait(timeout=10) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52892
diff
changeset
|
257 self.assertTrue(t.finished) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
258 if verbose: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
259 print(" all OK -- joining worker") |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
260 if t.finished: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
261 t.join() |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
262 # else the thread is still running, and we have no way to kill it |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
263 |
|
59203
9e8113e76adb
Merged revisions 78519 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
57160
diff
changeset
|
264 def test_limbo_cleanup(self): |
|
9e8113e76adb
Merged revisions 78519 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
57160
diff
changeset
|
265 # Issue 7481: Failure to start thread should cleanup the limbo map. |
|
9e8113e76adb
Merged revisions 78519 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
57160
diff
changeset
|
266 def fail_new_thread(*args): |
|
9e8113e76adb
Merged revisions 78519 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
57160
diff
changeset
|
267 raise threading.ThreadError() |
|
9e8113e76adb
Merged revisions 78519 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
57160
diff
changeset
|
268 _start_new_thread = threading._start_new_thread |
|
9e8113e76adb
Merged revisions 78519 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
57160
diff
changeset
|
269 threading._start_new_thread = fail_new_thread |
|
9e8113e76adb
Merged revisions 78519 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
57160
diff
changeset
|
270 try: |
|
9e8113e76adb
Merged revisions 78519 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
57160
diff
changeset
|
271 t = threading.Thread(target=lambda: None) |
|
59222
783f09b08706
Merged revisions 78538 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
59203
diff
changeset
|
272 self.assertRaises(threading.ThreadError, t.start) |
|
783f09b08706
Merged revisions 78538 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
59203
diff
changeset
|
273 self.assertFalse( |
|
783f09b08706
Merged revisions 78538 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
59203
diff
changeset
|
274 t in threading._limbo, |
|
783f09b08706
Merged revisions 78538 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
59203
diff
changeset
|
275 "Failed to cleanup _limbo map on failure of Thread.start().") |
|
59203
9e8113e76adb
Merged revisions 78519 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
57160
diff
changeset
|
276 finally: |
|
9e8113e76adb
Merged revisions 78519 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
57160
diff
changeset
|
277 threading._start_new_thread = _start_new_thread |
|
9e8113e76adb
Merged revisions 78519 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
57160
diff
changeset
|
278 |
|
44066
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
279 def test_finalize_runnning_thread(self): |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
280 # Issue 1402: the PyGILState_Ensure / _Release functions may be called |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
281 # very late on python exit: on deallocation of a running thread for |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
282 # example. |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
283 import_module("ctypes") |
|
44066
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
284 |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
285 rc, out, err = assert_python_failure("-c", """if 1: |
|
47266
7fe3a8648ce2
Rename thread to _thread and dummy_thread to _dummy_thread. Issue #2875.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
286 import ctypes, sys, time, _thread |
|
44066
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
287 |
|
45996
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
288 # This lock is used as a simple event variable. |
|
47266
7fe3a8648ce2
Rename thread to _thread and dummy_thread to _dummy_thread. Issue #2875.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
289 ready = _thread.allocate_lock() |
|
45996
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
290 ready.acquire() |
|
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
291 |
|
44066
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
292 # Module globals are cleared before __del__ is run |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
293 # So we save the functions in class dict |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
294 class C: |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
295 ensure = ctypes.pythonapi.PyGILState_Ensure |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
296 release = ctypes.pythonapi.PyGILState_Release |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
297 def __del__(self): |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
298 state = self.ensure() |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
299 self.release(state) |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
300 |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
301 def waitingThread(): |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
302 x = C() |
|
45996
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
303 ready.release() |
|
44066
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
304 time.sleep(100) |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
305 |
|
47266
7fe3a8648ce2
Rename thread to _thread and dummy_thread to _dummy_thread. Issue #2875.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
306 _thread.start_new_thread(waitingThread, ()) |
|
45996
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45495
diff
changeset
|
307 ready.acquire() # Be sure the other thread is waiting. |
|
44066
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
308 sys.exit(42) |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
309 """) |
|
44066
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
310 self.assertEqual(rc, 42) |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42084
diff
changeset
|
311 |
|
46304
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
312 def test_finalize_with_trace(self): |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
313 # Issue1733757 |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
314 # Avoid a deadlock when sys.settrace steps into threading._shutdown |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
315 assert_python_ok("-c", """if 1: |
|
46304
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
316 import sys, threading |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
317 |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
318 # A deadlock-killer, to prevent the |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
319 # testsuite to hang forever |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
320 def killer(): |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
321 import os, time |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
322 time.sleep(2) |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
323 print('program blocked; aborting') |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
324 os._exit(2) |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
325 t = threading.Thread(target=killer) |
|
48745
2614d501de9a
change is_daemon, set_daemon, get_name, and set_name to properties
Benjamin Peterson <benjamin@python.org>
parents:
48743
diff
changeset
|
326 t.daemon = True |
|
46304
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
327 t.start() |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
328 |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
329 # This is the trace function |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
330 def func(frame, event, arg): |
|
47615
045f83a1b864
Merged revisions 64125 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47555
diff
changeset
|
331 threading.current_thread() |
|
46304
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
332 return func |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
333 |
|
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
334 sys.settrace(func) |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
335 """) |
|
46304
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
336 |
|
56652
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
337 def test_join_nondaemon_on_shutdown(self): |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
338 # Issue 1722344 |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
339 # Raising SystemExit skipped threading._shutdown |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
340 rc, out, err = assert_python_ok("-c", """if 1: |
|
56652
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
341 import threading |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
342 from time import sleep |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
343 |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
344 def child(): |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
345 sleep(1) |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
346 # As a non-daemon thread we SHOULD wake up and nothing |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
347 # should be torn down yet |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
348 print("Woke up, sleep function is:", sleep) |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
349 |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
350 threading.Thread(target=child).start() |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
351 raise SystemExit |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
352 """) |
|
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
353 self.assertEqual(out.strip(), |
|
56695
161d332afc88
Merged revisions 75641 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56652
diff
changeset
|
354 b"Woke up, sleep function is: <built-in function sleep>") |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
355 self.assertEqual(err, b"") |
|
46304
3442e9e6b2cf
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46188
diff
changeset
|
356 |
|
44885
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
357 def test_enumerate_after_join(self): |
|
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
358 # Try hard to trigger #1703448: a thread is still returned in |
|
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
359 # threading.enumerate() after it has been join()ed. |
|
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
360 enum = threading.enumerate |
|
57218
32335ba3aa0b
Silence getcheckinterval()-related warnings in the test suite
Antoine Pitrou <solipsis@pitrou.net>
parents:
57209
diff
changeset
|
361 old_interval = sys.getswitchinterval() |
|
44885
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
362 try: |
|
46188
46348de63f61
Update test_threading with a couple changes from trunk that got lost due, I
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
46161
diff
changeset
|
363 for i in range(1, 100): |
|
57218
32335ba3aa0b
Silence getcheckinterval()-related warnings in the test suite
Antoine Pitrou <solipsis@pitrou.net>
parents:
57209
diff
changeset
|
364 sys.setswitchinterval(i * 0.0002) |
|
44885
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
365 t = threading.Thread(target=lambda: None) |
|
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
366 t.start() |
|
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
367 t.join() |
|
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
368 l = enum() |
|
58456
f0f221e1a7c0
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58415
diff
changeset
|
369 self.assertNotIn(t, l, |
|
44885
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
370 "#1703448 triggered after %d trials: %s" % (i, l)) |
|
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
371 finally: |
|
57218
32335ba3aa0b
Silence getcheckinterval()-related warnings in the test suite
Antoine Pitrou <solipsis@pitrou.net>
parents:
57209
diff
changeset
|
372 sys.setswitchinterval(old_interval) |
|
44885
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
373 |
|
45495
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
374 def test_no_refcycle_through_target(self): |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
375 class RunSelfFunction(object): |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
376 def __init__(self, should_raise): |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
377 # The links in this refcycle from Thread back to self |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
378 # should be cleaned up when the thread completes. |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
379 self.should_raise = should_raise |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
380 self.thread = threading.Thread(target=self._run, |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
381 args=(self,), |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
382 kwargs={'yet_another':self}) |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
383 self.thread.start() |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
384 |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
385 def _run(self, other_ref, yet_another): |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
386 if self.should_raise: |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
387 raise SystemExit |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
388 |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
389 cyclic_object = RunSelfFunction(should_raise=False) |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
390 weak_cyclic_object = weakref.ref(cyclic_object) |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
391 cyclic_object.thread.join() |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
392 del cyclic_object |
|
67397
8c448a4277a0
Issue 10825: Minor updates to the test suite.
Raymond Hettinger <python@rcn.com>
parents:
67371
diff
changeset
|
393 self.assertIsNone(weak_cyclic_object(), |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65885
diff
changeset
|
394 msg=('%d references still around' % |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65885
diff
changeset
|
395 sys.getrefcount(weak_cyclic_object()))) |
|
45495
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
396 |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
397 raising_cyclic_object = RunSelfFunction(should_raise=True) |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
398 weak_raising_cyclic_object = weakref.ref(raising_cyclic_object) |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
399 raising_cyclic_object.thread.join() |
|
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
400 del raising_cyclic_object |
|
67397
8c448a4277a0
Issue 10825: Minor updates to the test suite.
Raymond Hettinger <python@rcn.com>
parents:
67371
diff
changeset
|
401 self.assertIsNone(weak_raising_cyclic_object(), |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65885
diff
changeset
|
402 msg=('%d references still around' % |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65885
diff
changeset
|
403 sys.getrefcount(weak_raising_cyclic_object()))) |
|
45495
48488fa50729
Merged revisions 61003-61033 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44885
diff
changeset
|
404 |
|
48941
4fc480be1e4d
remove the deprecation warnings for the old threading API; update the docs
Benjamin Peterson <benjamin@python.org>
parents:
48766
diff
changeset
|
405 def test_old_threading_api(self): |
|
4fc480be1e4d
remove the deprecation warnings for the old threading API; update the docs
Benjamin Peterson <benjamin@python.org>
parents:
48766
diff
changeset
|
406 # Just a quick sanity check to make sure the old method names are |
|
4fc480be1e4d
remove the deprecation warnings for the old threading API; update the docs
Benjamin Peterson <benjamin@python.org>
parents:
48766
diff
changeset
|
407 # still present |
|
48757
54138ee20e57
add full deprecation warnings for old threading APIs
Benjamin Peterson <benjamin@python.org>
parents:
48745
diff
changeset
|
408 t = threading.Thread() |
|
48941
4fc480be1e4d
remove the deprecation warnings for the old threading API; update the docs
Benjamin Peterson <benjamin@python.org>
parents:
48766
diff
changeset
|
409 t.isDaemon() |
|
4fc480be1e4d
remove the deprecation warnings for the old threading API; update the docs
Benjamin Peterson <benjamin@python.org>
parents:
48766
diff
changeset
|
410 t.setDaemon(True) |
|
4fc480be1e4d
remove the deprecation warnings for the old threading API; update the docs
Benjamin Peterson <benjamin@python.org>
parents:
48766
diff
changeset
|
411 t.getName() |
|
4fc480be1e4d
remove the deprecation warnings for the old threading API; update the docs
Benjamin Peterson <benjamin@python.org>
parents:
48766
diff
changeset
|
412 t.setName("name") |
|
4fc480be1e4d
remove the deprecation warnings for the old threading API; update the docs
Benjamin Peterson <benjamin@python.org>
parents:
48766
diff
changeset
|
413 t.isAlive() |
|
4fc480be1e4d
remove the deprecation warnings for the old threading API; update the docs
Benjamin Peterson <benjamin@python.org>
parents:
48766
diff
changeset
|
414 e = threading.Event() |
|
4fc480be1e4d
remove the deprecation warnings for the old threading API; update the docs
Benjamin Peterson <benjamin@python.org>
parents:
48766
diff
changeset
|
415 e.isSet() |
|
4fc480be1e4d
remove the deprecation warnings for the old threading API; update the docs
Benjamin Peterson <benjamin@python.org>
parents:
48766
diff
changeset
|
416 threading.activeCount() |
|
48757
54138ee20e57
add full deprecation warnings for old threading APIs
Benjamin Peterson <benjamin@python.org>
parents:
48745
diff
changeset
|
417 |
|
63174
383e8463f56c
Tab test_repr_daemon over so it's included in ThreadTests.
Brian Curtin <brian.curtin@gmail.com>
parents:
63167
diff
changeset
|
418 def test_repr_daemon(self): |
|
383e8463f56c
Tab test_repr_daemon over so it's included in ThreadTests.
Brian Curtin <brian.curtin@gmail.com>
parents:
63167
diff
changeset
|
419 t = threading.Thread() |
|
383e8463f56c
Tab test_repr_daemon over so it's included in ThreadTests.
Brian Curtin <brian.curtin@gmail.com>
parents:
63167
diff
changeset
|
420 self.assertFalse('daemon' in repr(t)) |
|
383e8463f56c
Tab test_repr_daemon over so it's included in ThreadTests.
Brian Curtin <brian.curtin@gmail.com>
parents:
63167
diff
changeset
|
421 t.daemon = True |
|
383e8463f56c
Tab test_repr_daemon over so it's included in ThreadTests.
Brian Curtin <brian.curtin@gmail.com>
parents:
63167
diff
changeset
|
422 self.assertTrue('daemon' in repr(t)) |
|
44885
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
423 |
|
68155
f71acc4b2341
Issue #6064: Add a `daemon` keyword argument to the threading.Thread
Antoine Pitrou <solipsis@pitrou.net>
parents:
67397
diff
changeset
|
424 def test_deamon_param(self): |
|
f71acc4b2341
Issue #6064: Add a `daemon` keyword argument to the threading.Thread
Antoine Pitrou <solipsis@pitrou.net>
parents:
67397
diff
changeset
|
425 t = threading.Thread() |
|
f71acc4b2341
Issue #6064: Add a `daemon` keyword argument to the threading.Thread
Antoine Pitrou <solipsis@pitrou.net>
parents:
67397
diff
changeset
|
426 self.assertFalse(t.daemon) |
|
f71acc4b2341
Issue #6064: Add a `daemon` keyword argument to the threading.Thread
Antoine Pitrou <solipsis@pitrou.net>
parents:
67397
diff
changeset
|
427 t = threading.Thread(daemon=False) |
|
f71acc4b2341
Issue #6064: Add a `daemon` keyword argument to the threading.Thread
Antoine Pitrou <solipsis@pitrou.net>
parents:
67397
diff
changeset
|
428 self.assertFalse(t.daemon) |
|
f71acc4b2341
Issue #6064: Add a `daemon` keyword argument to the threading.Thread
Antoine Pitrou <solipsis@pitrou.net>
parents:
67397
diff
changeset
|
429 t = threading.Thread(daemon=True) |
|
f71acc4b2341
Issue #6064: Add a `daemon` keyword argument to the threading.Thread
Antoine Pitrou <solipsis@pitrou.net>
parents:
67397
diff
changeset
|
430 self.assertTrue(t.daemon) |
|
f71acc4b2341
Issue #6064: Add a `daemon` keyword argument to the threading.Thread
Antoine Pitrou <solipsis@pitrou.net>
parents:
67397
diff
changeset
|
431 |
|
76421
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
432 @unittest.skipUnless(hasattr(os, 'fork'), 'test needs fork()') |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
433 def test_dummy_thread_after_fork(self): |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
434 # Issue #14308: a dummy thread in the active list doesn't mess up |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
435 # the after-fork mechanism. |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
436 code = """if 1: |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
437 import _thread, threading, os, time |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
438 |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
439 def background_thread(evt): |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
440 # Creates and registers the _DummyThread instance |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
441 threading.current_thread() |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
442 evt.set() |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
443 time.sleep(10) |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
444 |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
445 evt = threading.Event() |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
446 _thread.start_new_thread(background_thread, (evt,)) |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
447 evt.wait() |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
448 assert threading.active_count() == 2, threading.active_count() |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
449 if os.fork() == 0: |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
450 assert threading.active_count() == 1, threading.active_count() |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
451 os._exit(0) |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
452 else: |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
453 os.wait() |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
454 """ |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
455 _, out, err = assert_python_ok("-c", code) |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
456 self.assertEqual(out, b'') |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
457 self.assertEqual(err, b'') |
|
41c64c700e1e
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
75916
diff
changeset
|
458 |
|
85463
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
459 @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
460 def test_is_alive_after_fork(self): |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
461 # Try hard to trigger #18418: is_alive() could sometimes be True on |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
462 # threads that vanished after a fork. |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
463 old_interval = sys.getswitchinterval() |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
464 self.addCleanup(sys.setswitchinterval, old_interval) |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
465 |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
466 # Make the bug more likely to manifest. |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
467 sys.setswitchinterval(1e-6) |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
468 |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
469 for i in range(20): |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
470 t = threading.Thread(target=lambda: None) |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
471 t.start() |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
472 self.addCleanup(t.join) |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
473 pid = os.fork() |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
474 if pid == 0: |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
475 os._exit(1 if t.is_alive() else 0) |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
476 else: |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
477 pid, status = os.waitpid(pid, 0) |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
478 self.assertEqual(0, status) |
|
29fce7f31539
Issue #18418: After fork(), reinit all threads states, not only active ones.
Charles-François Natali <cf.natali@gmail.com>
parents:
83510
diff
changeset
|
479 |
|
85520
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
480 def test_main_thread(self): |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
481 main = threading.main_thread() |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
482 self.assertEqual(main.name, 'MainThread') |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
483 self.assertEqual(main.ident, threading.current_thread().ident) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
484 self.assertEqual(main.ident, threading.get_ident()) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
485 |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
486 def f(): |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
487 self.assertNotEqual(threading.main_thread().ident, |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
488 threading.current_thread().ident) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
489 th = threading.Thread(target=f) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
490 th.start() |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
491 th.join() |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
492 |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
493 @unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()") |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
494 @unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()") |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
495 def test_main_thread_after_fork(self): |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
496 code = """if 1: |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
497 import os, threading |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
498 |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
499 pid = os.fork() |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
500 if pid == 0: |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
501 main = threading.main_thread() |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
502 print(main.name) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
503 print(main.ident == threading.current_thread().ident) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
504 print(main.ident == threading.get_ident()) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
505 else: |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
506 os.waitpid(pid, 0) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
507 """ |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
508 _, out, err = assert_python_ok("-c", code) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
509 data = out.decode().replace('\r', '') |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
510 self.assertEqual(err, b"") |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
511 self.assertEqual(data, "MainThread\nTrue\nTrue\n") |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
512 |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
513 @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug") |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
514 @unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()") |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
515 @unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()") |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
516 def test_main_thread_after_fork_from_nonmain_thread(self): |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
517 code = """if 1: |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
518 import os, threading, sys |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
519 |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
520 def f(): |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
521 pid = os.fork() |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
522 if pid == 0: |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
523 main = threading.main_thread() |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
524 print(main.name) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
525 print(main.ident == threading.current_thread().ident) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
526 print(main.ident == threading.get_ident()) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
527 # stdout is fully buffered because not a tty, |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
528 # we have to flush before exit. |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
529 sys.stdout.flush() |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
530 else: |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
531 os.waitpid(pid, 0) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
532 |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
533 th = threading.Thread(target=f) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
534 th.start() |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
535 th.join() |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
536 """ |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
537 _, out, err = assert_python_ok("-c", code) |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
538 data = out.decode().replace('\r', '') |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
539 self.assertEqual(err, b"") |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
540 self.assertEqual(data, "Thread-1\nTrue\nTrue\n") |
|
96e55a1a0de7
Issue #18882: Add threading.main_thread() function.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
85493
diff
changeset
|
541 |
|
85598
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
542 def test_tstate_lock(self): |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
543 # Test an implementation detail of Thread objects. |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
544 started = _thread.allocate_lock() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
545 finish = _thread.allocate_lock() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
546 started.acquire() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
547 finish.acquire() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
548 def f(): |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
549 started.release() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
550 finish.acquire() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
551 time.sleep(0.01) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
552 # The tstate lock is None until the thread is started |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
553 t = threading.Thread(target=f) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
554 self.assertIs(t._tstate_lock, None) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
555 t.start() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
556 started.acquire() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
557 self.assertTrue(t.is_alive()) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
558 # The tstate lock can't be acquired when the thread is running |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
559 # (or suspended). |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
560 tstate_lock = t._tstate_lock |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
561 self.assertFalse(tstate_lock.acquire(timeout=0), False) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
562 finish.release() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
563 # When the thread ends, the state_lock can be successfully |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
564 # acquired. |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
565 self.assertTrue(tstate_lock.acquire(timeout=5), False) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
566 # But is_alive() is still True: we hold _tstate_lock now, which |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
567 # prevents is_alive() from knowing the thread's end-of-life C code |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
568 # is done. |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
569 self.assertTrue(t.is_alive()) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
570 # Let is_alive() find out the C code is done. |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
571 tstate_lock.release() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
572 self.assertFalse(t.is_alive()) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
573 # And verify the thread disposed of _tstate_lock. |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
574 self.assertTrue(t._tstate_lock is None) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
575 |
|
85650
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
576 def test_repr_stopped(self): |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
577 # Verify that "stopped" shows up in repr(Thread) appropriately. |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
578 started = _thread.allocate_lock() |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
579 finish = _thread.allocate_lock() |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
580 started.acquire() |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
581 finish.acquire() |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
582 def f(): |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
583 started.release() |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
584 finish.acquire() |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
585 t = threading.Thread(target=f) |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
586 t.start() |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
587 started.acquire() |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
588 self.assertIn("started", repr(t)) |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
589 finish.release() |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
590 # "stopped" should appear in the repr in a reasonable amount of time. |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
591 # Implementation detail: as of this writing, that's trivially true |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
592 # if .join() is called, and almost trivially true if .is_alive() is |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
593 # called. The detail we're testing here is that "stopped" shows up |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
594 # "all on its own". |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
595 LOOKING_FOR = "stopped" |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
596 for i in range(500): |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
597 if LOOKING_FOR in repr(t): |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
598 break |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
599 time.sleep(0.01) |
|
967af1815967
Get "stopped" back into repr(Thread) when appropriate.
Tim Peters <tim@python.org>
parents:
85631
diff
changeset
|
600 self.assertIn(LOOKING_FOR, repr(t)) # we waited at least 5 seconds |
|
44885
fefaa0e66fdd
Merged revisions 60176-60209 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
601 |
|
86165
e06edc0c7a49
Issue 19158: a rare race in BoundedSemaphore could allow .release() too often.
Tim Peters <tim@python.org>
parents:
85492
diff
changeset
|
602 def test_BoundedSemaphore_limit(self): |
| 86168 | 603 # BoundedSemaphore should raise ValueError if released too often. |
| 604 for limit in range(1, 10): | |
| 605 bs = threading.BoundedSemaphore(limit) | |
| 606 threads = [threading.Thread(target=bs.acquire) | |
| 607 for _ in range(limit)] | |
| 608 for t in threads: | |
| 609 t.start() | |
| 610 for t in threads: | |
| 611 t.join() | |
| 612 threads = [threading.Thread(target=bs.release) | |
| 613 for _ in range(limit)] | |
| 614 for t in threads: | |
| 615 t.start() | |
| 616 for t in threads: | |
| 617 t.join() | |
| 618 self.assertRaises(ValueError, bs.release) | |
|
86165
e06edc0c7a49
Issue 19158: a rare race in BoundedSemaphore could allow .release() too often.
Tim Peters <tim@python.org>
parents:
85492
diff
changeset
|
619 |
|
87070
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
620 def test_locals_at_exit(self): |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
621 # Issue #19466: thread locals must not be deleted before destructors |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
622 # are called |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
623 rc, out, err = assert_python_ok("-c", """if 1: |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
624 import threading |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
625 |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
626 class Atexit: |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
627 def __del__(self): |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
628 print("thread_dict.atexit = %r" % thread_dict.atexit) |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
629 |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
630 thread_dict = threading.local() |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
631 thread_dict.atexit = "atexit" |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
632 |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
633 atexit = Atexit() |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
634 """) |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
635 self.assertEqual(out.rstrip(), b"thread_dict.atexit = 'atexit'") |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
636 |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
637 def test_warnings_at_exit(self): |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
638 # Issue #19466: try to call most destructors at Python shutdown before |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
639 # destroying Python thread states |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
640 filename = __file__ |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
641 rc, out, err = assert_python_ok("-Wd", "-c", """if 1: |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
642 import time |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
643 import threading |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
644 |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
645 def open_sleep(): |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
646 # a warning will be emitted when the open file will be |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
647 # destroyed (without being explicitly closed) while the daemon |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
648 # thread is destroyed |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
649 fileobj = open(%a, 'rb') |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
650 start_event.set() |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
651 time.sleep(60.0) |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
652 |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
653 start_event = threading.Event() |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
654 |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
655 thread = threading.Thread(target=open_sleep) |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
656 thread.daemon = True |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
657 thread.start() |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
658 |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
659 # wait until the thread started |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
660 start_event.wait() |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
661 """ % filename) |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
662 self.assertRegex(err.rstrip(), |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
663 b"^sys:1: ResourceWarning: unclosed file ") |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
664 |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
665 |
|
56883
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
666 class ThreadJoinOnShutdown(BaseTestCase): |
| 48516 | 667 |
| 668 def _run_and_join(self, script): | |
| 669 script = """if 1: | |
| 670 import sys, os, time, threading | |
| 671 | |
| 672 # a thread, which waits for the main program to terminate | |
| 673 def joiningfunc(mainthread): | |
| 674 mainthread.join() | |
| 675 print('end of thread') | |
|
49058
179f8d89ad19
Issue #874900: fix behaviour of threading module after a fork.
Antoine Pitrou <solipsis@pitrou.net>
parents:
48941
diff
changeset
|
676 # stdout is fully buffered because not a tty, we have to flush |
|
179f8d89ad19
Issue #874900: fix behaviour of threading module after a fork.
Antoine Pitrou <solipsis@pitrou.net>
parents:
48941
diff
changeset
|
677 # before exit. |
|
179f8d89ad19
Issue #874900: fix behaviour of threading module after a fork.
Antoine Pitrou <solipsis@pitrou.net>
parents:
48941
diff
changeset
|
678 sys.stdout.flush() |
| 48516 | 679 \n""" + script |
| 680 | |
|
69855
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
681 rc, out, err = assert_python_ok("-c", script) |
|
97a4855202b8
Use shared testing facilities in test_threading
Antoine Pitrou <solipsis@pitrou.net>
parents:
69832
diff
changeset
|
682 data = out.decode().replace('\r', '') |
|
48518
991cadd47d97
Merged revisions 65059 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48517
diff
changeset
|
683 self.assertEqual(data, "end of main\nend of thread\n") |
| 48516 | 684 |
| 685 def test_1_join_on_shutdown(self): | |
| 686 # The usual case: on exit, wait for a non-daemon thread | |
| 687 script = """if 1: | |
| 688 import os | |
| 689 t = threading.Thread(target=joiningfunc, | |
| 690 args=(threading.current_thread(),)) | |
| 691 t.start() | |
| 692 time.sleep(0.1) | |
| 693 print('end of main') | |
| 694 """ | |
| 695 self._run_and_join(script) | |
| 696 | |
|
55402
df5a70860781
Use unittest.SkipTest to skip tests in test_threading.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55401
diff
changeset
|
697 @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") |
|
71112
0ed5e6ff10f8
Issue #11870: Skip test_threading.test_2_join_in_forked_process() on platforms
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71097
diff
changeset
|
698 @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug") |
| 48516 | 699 def test_2_join_in_forked_process(self): |
| 700 # Like the test above, but from a forked interpreter | |
| 701 script = """if 1: | |
| 702 childpid = os.fork() | |
| 703 if childpid != 0: | |
| 704 os.waitpid(childpid, 0) | |
| 705 sys.exit(0) | |
| 706 | |
| 707 t = threading.Thread(target=joiningfunc, | |
| 708 args=(threading.current_thread(),)) | |
| 709 t.start() | |
| 710 print('end of main') | |
| 711 """ | |
| 712 self._run_and_join(script) | |
| 713 | |
|
55402
df5a70860781
Use unittest.SkipTest to skip tests in test_threading.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55401
diff
changeset
|
714 @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") |
|
71112
0ed5e6ff10f8
Issue #11870: Skip test_threading.test_2_join_in_forked_process() on platforms
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71097
diff
changeset
|
715 @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug") |
|
49058
179f8d89ad19
Issue #874900: fix behaviour of threading module after a fork.
Antoine Pitrou <solipsis@pitrou.net>
parents:
48941
diff
changeset
|
716 def test_3_join_in_forked_from_thread(self): |
| 48516 | 717 # Like the test above, but fork() was called from a worker thread |
| 718 # In the forked process, the main Thread object must be marked as stopped. | |
|
55402
df5a70860781
Use unittest.SkipTest to skip tests in test_threading.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55401
diff
changeset
|
719 |
| 48516 | 720 script = """if 1: |
| 721 main_thread = threading.current_thread() | |
| 722 def worker(): | |
| 723 childpid = os.fork() | |
| 724 if childpid != 0: | |
| 725 os.waitpid(childpid, 0) | |
| 726 sys.exit(0) | |
| 727 | |
| 728 t = threading.Thread(target=joiningfunc, | |
| 729 args=(main_thread,)) | |
| 730 print('end of main') | |
| 731 t.start() | |
| 732 t.join() # Should not block: main_thread is already stopped | |
| 733 | |
| 734 w = threading.Thread(target=worker) | |
| 735 w.start() | |
| 736 """ | |
| 737 self._run_and_join(script) | |
| 738 | |
|
71112
0ed5e6ff10f8
Issue #11870: Skip test_threading.test_2_join_in_forked_process() on platforms
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71097
diff
changeset
|
739 @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug") |
|
85631
aff959a3ba13
Issue 18984: Remove ._stopped Event from Thread internals.
Tim Peters <tim@python.org>
parents:
85623
diff
changeset
|
740 def test_4_daemon_threads(self): |
|
69832
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
741 # Check that a daemon thread cannot crash the interpreter on shutdown |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
742 # by manipulating internal structures that are being disposed of in |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
743 # the main thread. |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
744 script = """if True: |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
745 import os |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
746 import random |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
747 import sys |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
748 import time |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
749 import threading |
|
87070
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
750 import warnings |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
751 |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
752 # ignore "unclosed file ..." warnings |
|
c2a13acd5e2b
Close #19466: Clear the frames of daemon threads earlier during the Python
Victor Stinner <victor.stinner@gmail.com>
parents:
86168
diff
changeset
|
753 warnings.filterwarnings('ignore', '', ResourceWarning) |
| 48516 | 754 |
|
69832
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
755 thread_has_run = set() |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
756 |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
757 def random_io(): |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
758 '''Loop for a while sleeping random tiny amounts and doing some I/O.''' |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
759 while True: |
|
71097
68bc1a29ba5a
Issue #12451: Open files in binary mode in some tests when the text file is not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
70449
diff
changeset
|
760 in_f = open(os.__file__, 'rb') |
|
69832
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
761 stuff = in_f.read(200) |
|
71097
68bc1a29ba5a
Issue #12451: Open files in binary mode in some tests when the text file is not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
70449
diff
changeset
|
762 null_f = open(os.devnull, 'wb') |
|
69832
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
763 null_f.write(stuff) |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
764 time.sleep(random.random() / 1995) |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
765 null_f.close() |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
766 in_f.close() |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
767 thread_has_run.add(threading.current_thread()) |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
768 |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
769 def main(): |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
770 count = 0 |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
771 for _ in range(40): |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
772 new_thread = threading.Thread(target=random_io) |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
773 new_thread.daemon = True |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
774 new_thread.start() |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
775 count += 1 |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
776 while len(thread_has_run) < count: |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
777 time.sleep(0.001) |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
778 # Trigger process shutdown |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
779 sys.exit(0) |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
780 |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
781 main() |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
782 """ |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
783 rc, out, err = assert_python_ok('-c', script) |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
784 self.assertFalse(err) |
|
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
785 |
|
74730
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
786 @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") |
|
74830
29b83d3d40d0
Skip test_threading.test_reinit_tls_after_fork() on platforms where fork()
Charles-François Natali <neologix@free.fr>
parents:
74730
diff
changeset
|
787 @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug") |
|
74730
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
788 def test_reinit_tls_after_fork(self): |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
789 # Issue #13817: fork() would deadlock in a multithreaded program with |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
790 # the ad-hoc TLS implementation. |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
791 |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
792 def do_fork_and_wait(): |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
793 # just fork a child process and wait it |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
794 pid = os.fork() |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
795 if pid > 0: |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
796 os.waitpid(pid, 0) |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
797 else: |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
798 os._exit(0) |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
799 |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
800 # start a bunch of threads that will fork() child processes |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
801 threads = [] |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
802 for i in range(16): |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
803 t = threading.Thread(target=do_fork_and_wait) |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
804 threads.append(t) |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
805 t.start() |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
806 |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
807 for t in threads: |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
808 t.join() |
|
7b24dd587a7b
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
Charles-François Natali <neologix@free.fr>
parents:
74665
diff
changeset
|
809 |
|
83630
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
810 @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
811 def test_clear_threads_states_after_fork(self): |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
812 # Issue #17094: check that threads states are cleared after fork() |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
813 |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
814 # start a bunch of threads |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
815 threads = [] |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
816 for i in range(16): |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
817 t = threading.Thread(target=lambda : time.sleep(0.3)) |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
818 threads.append(t) |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
819 t.start() |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
820 |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
821 pid = os.fork() |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
822 if pid == 0: |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
823 # check that threads states have been cleared |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
824 if len(sys._current_frames()) == 1: |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
825 os._exit(0) |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
826 else: |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
827 os._exit(1) |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
828 else: |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
829 _, status = os.waitpid(pid, 0) |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
830 self.assertEqual(0, status) |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
831 |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
832 for t in threads: |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
833 t.join() |
|
847692b9902a
Issue #17094: Clear stale thread states after fork().
Antoine Pitrou <solipsis@pitrou.net>
parents:
83511
diff
changeset
|
834 |
| 48516 | 835 |
|
85398
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
836 class SubinterpThreadingTests(BaseTestCase): |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
837 |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
838 def test_threads_join(self): |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
839 # Non-daemon threads should be joined at subinterpreter shutdown |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
840 # (issue #18808) |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
841 r, w = os.pipe() |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
842 self.addCleanup(os.close, r) |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
843 self.addCleanup(os.close, w) |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
844 code = r"""if 1: |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
845 import os |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
846 import threading |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
847 import time |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
848 |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
849 def f(): |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
850 # Sleep a bit so that the thread is still running when |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
851 # Py_EndInterpreter is called. |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
852 time.sleep(0.05) |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
853 os.write(%d, b"x") |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
854 threading.Thread(target=f).start() |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
855 """ % (w,) |
|
87401
6e2089dbc5ad
Issue #18874: Implement the PEP 454 (tracemalloc)
Victor Stinner <victor.stinner@gmail.com>
parents:
87070
diff
changeset
|
856 ret = test.support.run_in_subinterp(code) |
|
85398
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
857 self.assertEqual(ret, 0) |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
858 # The thread was joined properly. |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
859 self.assertEqual(os.read(r, 1), b"x") |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
860 |
|
85598
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
861 def test_threads_join_2(self): |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
862 # Same as above, but a delay gets introduced after the thread's |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
863 # Python code returned but before the thread state is deleted. |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
864 # To achieve this, we register a thread-local object which sleeps |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
865 # a bit when deallocated. |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
866 r, w = os.pipe() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
867 self.addCleanup(os.close, r) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
868 self.addCleanup(os.close, w) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
869 code = r"""if 1: |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
870 import os |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
871 import threading |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
872 import time |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
873 |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
874 class Sleeper: |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
875 def __del__(self): |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
876 time.sleep(0.05) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
877 |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
878 tls = threading.local() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
879 |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
880 def f(): |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
881 # Sleep a bit so that the thread is still running when |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
882 # Py_EndInterpreter is called. |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
883 time.sleep(0.05) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
884 tls.x = Sleeper() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
885 os.write(%d, b"x") |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
886 threading.Thread(target=f).start() |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
887 """ % (w,) |
|
87401
6e2089dbc5ad
Issue #18874: Implement the PEP 454 (tracemalloc)
Victor Stinner <victor.stinner@gmail.com>
parents:
87070
diff
changeset
|
888 ret = test.support.run_in_subinterp(code) |
|
85598
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
889 self.assertEqual(ret, 0) |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
890 # The thread was joined properly. |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
891 self.assertEqual(os.read(r, 1), b"x") |
|
d52b68edbca6
Issue #18808: Thread.join() now waits for the underlying thread state to be destroyed before returning.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85520
diff
changeset
|
892 |
|
85398
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
893 def test_daemon_threads_fatal_error(self): |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
894 subinterp_code = r"""if 1: |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
895 import os |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
896 import threading |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
897 import time |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
898 |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
899 def f(): |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
900 # Make sure the daemon thread is still running when |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
901 # Py_EndInterpreter is called. |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
902 time.sleep(10) |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
903 threading.Thread(target=f, daemon=True).start() |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
904 """ |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
905 script = r"""if 1: |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
906 import _testcapi |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
907 |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
908 _testcapi.run_in_subinterp(%r) |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
909 """ % (subinterp_code,) |
|
86164
1cbd3d9f7d61
Issue #18948: improve SuppressCoreFiles to include Windows crash popup suppression, and use it in more tests.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85650
diff
changeset
|
910 with test.support.SuppressCrashReport(): |
|
1cbd3d9f7d61
Issue #18948: improve SuppressCoreFiles to include Windows crash popup suppression, and use it in more tests.
Antoine Pitrou <solipsis@pitrou.net>
parents:
85650
diff
changeset
|
911 rc, out, err = assert_python_failure("-c", script) |
|
85398
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
912 self.assertIn("Fatal Python error: Py_EndInterpreter: " |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
913 "not the last thread", err.decode()) |
|
becbb65074e1
Issue #18808: Non-daemon threads are now automatically joined when a sub-interpreter is shutdown (it would previously dump a fatal error).
Antoine Pitrou <solipsis@pitrou.net>
parents:
83630
diff
changeset
|
914 |
| 48516 | 915 |
|
56883
e4bfbe9b74c8
Merged revisions 75851 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56694
diff
changeset
|
916 class ThreadingExceptionTests(BaseTestCase): |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
917 # A RuntimeError should be raised if Thread.start() is called |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
918 # multiple times. |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
919 def test_start_thread_again(self): |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
920 thread = threading.Thread() |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
921 thread.start() |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
922 self.assertRaises(RuntimeError, thread.start) |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
923 |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
924 def test_joining_current_thread(self): |
|
47615
045f83a1b864
Merged revisions 64125 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47555
diff
changeset
|
925 current_thread = threading.current_thread() |
|
045f83a1b864
Merged revisions 64125 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47555
diff
changeset
|
926 self.assertRaises(RuntimeError, current_thread.join); |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
927 |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
928 def test_joining_inactive_thread(self): |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
929 thread = threading.Thread() |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
930 self.assertRaises(RuntimeError, thread.join) |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
931 |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
932 def test_daemonize_active_thread(self): |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
933 thread = threading.Thread() |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
934 thread.start() |
|
48745
2614d501de9a
change is_daemon, set_daemon, get_name, and set_name to properties
Benjamin Peterson <benjamin@python.org>
parents:
48743
diff
changeset
|
935 self.assertRaises(RuntimeError, setattr, thread, "daemon", True) |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
936 |
|
68191
2ddca55e098d
Issue #11140: Lock.release() now raises a RuntimeError when attempting
Antoine Pitrou <solipsis@pitrou.net>
parents:
68155
diff
changeset
|
937 def test_releasing_unacquired_lock(self): |
|
2ddca55e098d
Issue #11140: Lock.release() now raises a RuntimeError when attempting
Antoine Pitrou <solipsis@pitrou.net>
parents:
68155
diff
changeset
|
938 lock = threading.Lock() |
|
2ddca55e098d
Issue #11140: Lock.release() now raises a RuntimeError when attempting
Antoine Pitrou <solipsis@pitrou.net>
parents:
68155
diff
changeset
|
939 self.assertRaises(RuntimeError, lock.release) |
|
2ddca55e098d
Issue #11140: Lock.release() now raises a RuntimeError when attempting
Antoine Pitrou <solipsis@pitrou.net>
parents:
68155
diff
changeset
|
940 |
|
83510
9755036c81d0
backported rev 79713 from 3.4, test_recursion_limit skipped for -O0
Łukasz Langa <lukasz@langa.pl>
parents:
83029
diff
changeset
|
941 @unittest.skipUnless(sys.platform == 'darwin' and test.support.python_is_optimized(), |
|
9755036c81d0
backported rev 79713 from 3.4, test_recursion_limit skipped for -O0
Łukasz Langa <lukasz@langa.pl>
parents:
83029
diff
changeset
|
942 'test macosx problem') |
|
70448
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
943 def test_recursion_limit(self): |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
944 # Issue 9670 |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
945 # test that excessive recursion within a non-main thread causes |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
946 # an exception rather than crashing the interpreter on platforms |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
947 # like Mac OS X or FreeBSD which have small default stack sizes |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
948 # for threads |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
949 script = """if True: |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
950 import threading |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
951 |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
952 def recurse(): |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
953 return recurse() |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
954 |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
955 def outer(): |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
956 try: |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
957 recurse() |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
958 except RuntimeError: |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
959 pass |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
960 |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
961 w = threading.Thread(target=outer) |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
962 w.start() |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
963 w.join() |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
964 print('end of main thread') |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
965 """ |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
966 expected_output = "end of main thread\n" |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
967 p = subprocess.Popen([sys.executable, "-c", script], |
|
77853
175dab427bfb
Better diagnose test failure
Antoine Pitrou <solipsis@pitrou.net>
parents:
76421
diff
changeset
|
968 stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
70448
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
969 stdout, stderr = p.communicate() |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
970 data = stdout.decode().replace('\r', '') |
|
77853
175dab427bfb
Better diagnose test failure
Antoine Pitrou <solipsis@pitrou.net>
parents:
76421
diff
changeset
|
971 self.assertEqual(p.returncode, 0, "Unexpected error: " + stderr.decode()) |
|
70448
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
972 self.assertEqual(data, expected_output) |
|
57160
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
973 |
|
83029
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
974 class TimerTests(BaseTestCase): |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
975 |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
976 def setUp(self): |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
977 BaseTestCase.setUp(self) |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
978 self.callback_args = [] |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
979 self.callback_event = threading.Event() |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
980 |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
981 def test_init_immutable_default_args(self): |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
982 # Issue 17435: constructor defaults were mutable objects, they could be |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
983 # mutated via the object attributes and affect other Timer objects. |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
984 timer1 = threading.Timer(0.01, self._callback_spy) |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
985 timer1.start() |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
986 self.callback_event.wait() |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
987 timer1.args.append("blah") |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
988 timer1.kwargs["foo"] = "bar" |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
989 self.callback_event.clear() |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
990 timer2 = threading.Timer(0.01, self._callback_spy) |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
991 timer2.start() |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
992 self.callback_event.wait() |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
993 self.assertEqual(len(self.callback_args), 2) |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
994 self.assertEqual(self.callback_args, [((), {}), ((), {})]) |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
995 |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
996 def _callback_spy(self, *args, **kwargs): |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
997 self.callback_args.append((args[:], kwargs.copy())) |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
998 self.callback_event.set() |
|
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
999 |
|
57160
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1000 class LockTests(lock_tests.LockTests): |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1001 locktype = staticmethod(threading.Lock) |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1002 |
|
57172
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
57158
diff
changeset
|
1003 class PyRLockTests(lock_tests.RLockTests): |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
57158
diff
changeset
|
1004 locktype = staticmethod(threading._PyRLock) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
57158
diff
changeset
|
1005 |
|
74665
5cf181df7bea
Issue #13894: Skip test_threading.CRLockTests if _CRLock isn't available. Patch
Charles-François Natali <neologix@free.fr>
parents:
71112
diff
changeset
|
1006 @unittest.skipIf(threading._CRLock is None, 'RLock not implemented in C') |
|
57172
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
57158
diff
changeset
|
1007 class CRLockTests(lock_tests.RLockTests): |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
57158
diff
changeset
|
1008 locktype = staticmethod(threading._CRLock) |
|
57160
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1009 |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1010 class EventTests(lock_tests.EventTests): |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1011 eventtype = staticmethod(threading.Event) |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1012 |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1013 class ConditionAsRLockTests(lock_tests.RLockTests): |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1014 # An Condition uses an RLock by default and exports its API. |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1015 locktype = staticmethod(threading.Condition) |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1016 |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1017 class ConditionTests(lock_tests.ConditionTests): |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1018 condtype = staticmethod(threading.Condition) |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1019 |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1020 class SemaphoreTests(lock_tests.SemaphoreTests): |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1021 semtype = staticmethod(threading.Semaphore) |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1022 |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1023 class BoundedSemaphoreTests(lock_tests.BoundedSemaphoreTests): |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1024 semtype = staticmethod(threading.BoundedSemaphore) |
|
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1025 |
|
65677
5a882f789ec1
issue 8777
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
65428
diff
changeset
|
1026 class BarrierTests(lock_tests.BarrierTests): |
|
5a882f789ec1
issue 8777
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
65428
diff
changeset
|
1027 barriertype = staticmethod(threading.Barrier) |
|
57160
fe33562d1f95
Merged revisions 76138,76173 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57141
diff
changeset
|
1028 |
|
34362
cc27b249755d
Converted to a unittest. Added checks that the bounded semaphore actually
Tim Peters <tim.peters@gmail.com>
parents:
24364
diff
changeset
|
1029 if __name__ == "__main__": |
|
83029
2698920eadcd
Issue #17435: Don't use mutable default values in Timer.
R David Murray <rdmurray@bitdance.com>
parents:
81566
diff
changeset
|
1030 unittest.main() |
