File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -444,16 +444,19 @@ held. Any future finalizer that wanted to acquire the lock would be deadlocked!
444444 {
445445 assert(PyThreadState_GetUnchecked() != NULL);
446446 PyInterpreterState *interp = PyInterpreterState_Hold();
447+ / * Temporarily make this thread non-daemon to ensure that the
448+ lock is released. */
447449 if (PyThreadState_Ensure(interp) < 0) {
448- PyErr_SetString(PyExc_RuntimeError, "interpreter is shutting down");
450+ PyErr_SetString(PyExc_PythonFinalizationError,
451+ "interpreter is shutting down");
449452 return NULL;
450453 }
451454
452455 Py_BEGIN_ALLOW_THREADS;
453456 acquire_some_lock();
454457 Py_END_ALLOW_THREADS;
455458
456- /* Do something with the lock */
459+ /* Do something while holding the lock */
457460 // ...
458461
459462 release_some_lock();
@@ -525,6 +528,7 @@ This is the same code, updated to use the new functions:
525528
526529 PyInterpreterState *interp = PyInterpreterState_Hold();
527530 if (PyThread_start_joinable_thread(thread_func, interp, &ident, &handle) < 0) {
531+ PyInterpreterState_Release(interp);
528532 return NULL;
529533 }
530534 Py_BEGIN_ALLOW_THREADS
You can’t perform that action at this time.
0 commit comments