Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 91d94d9

Browse filesBrowse files
committed
Fix daemon thread shutdown.
1 parent b14aa73 commit 91d94d9
Copy full SHA for 91d94d9

File tree

Expand file treeCollapse file tree

2 files changed

+9
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-6
lines changed

‎Lib/test/test_interpreters/test_api.py

Copy file name to clipboardExpand all lines: Lib/test/test_interpreters/test_api.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ def test_remaining_daemon_threads(self):
691691
import time
692692
693693
def task():
694-
time.sleep(100)
694+
time.sleep(3)
695695
696696
threads = [threading.Thread(target=task, daemon=True) for _ in range(3)]
697697
for t in threads:

‎Python/pylifecycle.c

Copy file name to clipboardExpand all lines: Python/pylifecycle.c
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,14 +2449,17 @@ Py_EndInterpreter(PyThreadState *tstate)
24492449
_Py_FinishPendingCalls(tstate);
24502450

24512451
_PyAtExit_Call(tstate->interp);
2452-
_PyRuntimeState *runtime = interp->runtime;
2453-
_PyEval_StopTheWorldAll(runtime);
2454-
PyThreadState *list = _PyThreadState_RemoveExcept(tstate);
2455-
2452+
_PyEval_StopTheWorld(interp);
24562453
/* Remaining daemon threads will automatically exit
24572454
when they attempt to take the GIL (ex: PyEval_RestoreThread()). */
24582455
_PyInterpreterState_SetFinalizing(interp, tstate);
2459-
_PyEval_StartTheWorldAll(runtime);
2456+
2457+
PyThreadState *list = _PyThreadState_RemoveExcept(tstate);
2458+
for (PyThreadState *p = list; p != NULL; p = p->next) {
2459+
_PyThreadState_SetShuttingDown(p);
2460+
}
2461+
2462+
_PyEval_StartTheWorld(interp);
24602463
_PyThreadState_DeleteList(list, /*is_after_fork=*/0);
24612464

24622465
// XXX Call something like _PyImport_Disable() here?

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.