Skip to content

Commit 0cecc22

Browse files
authored
bpo-20891: Remove test_capi.test_bpo20891() (python#5425)
My first fix is not enough to make test_bpo20891() reliable. A second fix is needed and it was decided to not backport it, so remove the test instead. For Python 3.6, the workaround is to call PyEval_InitThreads() before spawning the first C thread. Python 3.7 will have both fixes.
1 parent 757aad6 commit 0cecc22

File tree

2 files changed

+0
-61
lines changed

2 files changed

+0
-61
lines changed

Lib/test/test_capi.py

-13
Original file line numberDiff line numberDiff line change
@@ -494,19 +494,6 @@ def test_pre_initialization_api(self):
494494
self.assertEqual(out, '')
495495
self.assertEqual(err, '')
496496

497-
@unittest.skipIf(True,
498-
"FIXME: test fails randomly because of a race conditon, "
499-
"see bpo-20891")
500-
def test_bpo20891(self):
501-
"""
502-
bpo-20891: Calling PyGILState_Ensure in a non-Python thread before
503-
calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must
504-
call PyEval_InitThreads() for us in this case.
505-
"""
506-
out, err = self.run_embedded_interpreter("bpo20891")
507-
self.assertEqual(out, '')
508-
self.assertEqual(err, '')
509-
510497

511498
class SkipitemTest(unittest.TestCase):
512499

Programs/_testembed.c

-48
Original file line numberDiff line numberDiff line change
@@ -149,53 +149,6 @@ static int test_pre_initialization_api(void)
149149
return 0;
150150
}
151151

152-
static void bpo20891_thread(void *lockp)
153-
{
154-
PyThread_type_lock lock = *((PyThread_type_lock*)lockp);
155-
156-
PyGILState_STATE state = PyGILState_Ensure();
157-
if (!PyGILState_Check()) {
158-
fprintf(stderr, "PyGILState_Check failed!");
159-
abort();
160-
}
161-
162-
PyGILState_Release(state);
163-
164-
PyThread_release_lock(lock);
165-
166-
PyThread_exit_thread();
167-
}
168-
169-
static int test_bpo20891(void)
170-
{
171-
/* bpo-20891: Calling PyGILState_Ensure in a non-Python thread before
172-
calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must
173-
call PyEval_InitThreads() for us in this case. */
174-
PyThread_type_lock lock = PyThread_allocate_lock();
175-
if (!lock) {
176-
fprintf(stderr, "PyThread_allocate_lock failed!");
177-
return 1;
178-
}
179-
180-
_testembed_Py_Initialize();
181-
182-
long thrd = PyThread_start_new_thread(bpo20891_thread, &lock);
183-
if (thrd == -1) {
184-
fprintf(stderr, "PyThread_start_new_thread failed!");
185-
return 1;
186-
}
187-
PyThread_acquire_lock(lock, WAIT_LOCK);
188-
189-
Py_BEGIN_ALLOW_THREADS
190-
/* wait until the thread exit */
191-
PyThread_acquire_lock(lock, WAIT_LOCK);
192-
Py_END_ALLOW_THREADS
193-
194-
PyThread_free_lock(lock);
195-
196-
return 0;
197-
}
198-
199152

200153
/* *********************************************************
201154
* List of test cases and the function that implements it.
@@ -219,7 +172,6 @@ static struct TestCase TestCases[] = {
219172
{ "forced_io_encoding", test_forced_io_encoding },
220173
{ "repeated_init_and_subinterpreters", test_repeated_init_and_subinterpreters },
221174
{ "pre_initialization_api", test_pre_initialization_api },
222-
{ "bpo20891", test_bpo20891 },
223175
{ NULL, NULL }
224176
};
225177

0 commit comments

Comments
 (0)