Python 3.14: crash or hang at exit while daemon threads scan object/Arrow data (not fixed by #709)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 38/100
調査の方向性
Start with the two failing cases in tests/slow/test_interpreter_shutdown.py and compare the object and Arrow scan paths with the numeric and string[pyarrow] cases that pass. Read the related issues #601, #638, #531, and #709, then investigate how scan callbacks acquire the GIL during Python 3.14 finalization. Done means both cases exit reliably without crashes or hangs on 3.14 while the unaffected cases continue to pass.
索引モデルが issue の本文から書いたものです。
説明
What happens?
On Python 3.14, a process whose daemon threads are still running queries that scan Python objects (an object-dtype pandas column, or a pyarrow table) crashes or hangs at interpreter exit. The same scripts exit cleanly on Python 3.13.
These are the daemon_threads_scanning_object_frame_at_exit and daemon_threads_scanning_one_chunk_arrow_table_at_exit cases in tests/slow/test_interpreter_shutdown.py. They fail intermittently on 3.14. Daemon threads that scan numeric or string[pyarrow] frames, or that only run range() queries, never fail.
#709 (end every open result before the interpreter finalizes) helps the object-frame case (37 → 11 failures per 100) but not the Arrow-table case (7 → 9), so this looks like a separate path: DuckDB's worker threads still enter the Python C API during 3.14 finalization, while the daemon threads' queries are running.
Failure signatures (a mix, from run to run):
- SIGSEGV, exit status -11, usually right after nanobind's leak report
double free or corruption (out)followed byFatal Python error: PyInterpreterState_Delete: remaining threads(Python runtime state: finalizing)Fatal Python error: PyGILState_Release: auto-releasing thread-state, but no thread-state for this threadFatal Python error: gilstate_tss_set: failed to set current tstate (TSS)- On Windows (CI): exit status
0xC0000409(STATUS_STACK_BUFFER_OVERRUN) - A hang at exit: the process never terminates and has to be killed
Failures per 100 runs of each test case, using the test's own pass rule. Linux aarch64, 12 runs in parallel:
| build | Python | object_frame |
one_chunk_arrow_table |
|---|---|---|---|
duckdb==2.0.0 (PyPI wheel) |
3.14.7 | 37 | 7 |
duckdb==2.0.0 (PyPI wheel) |
3.13.15 | 0 | 0 |
| downstream build of v2.0.0 with #709 cherry-picked (and its test updates) | 3.14.7 | 11 | 9 |
| same | 3.13.15 | 0 | 0 |
With 3 runs in parallel, duckdb==2.0.0 on 3.14.7 failed 19 (object_frame) and 17 (one_chunk_arrow_table) out of 100. We have also seen both cases fail on macOS arm64 and Windows amd64 CI runners with the cp312-abi3 wheel on 3.14.
Possibly related: #601 (don't touch Python state from destructors that outlive the interpreter), #638 and #531.
One possible direction: before a scan callback takes the GIL from a DuckDB worker thread, check Py_IsFinalizing() (or _Py_IsFinalizing()). If finalization has started, fail the task with an interrupt instead of calling PyGILState_Ensure. Together with #709's atexit hook, that would cover a query that starts or resumes after the hook has run.
To Reproduce
import threading
import time
import duckdb
import pandas as pd
frame = pd.DataFrame({"a": pd.Series([f"v{i % 100}" for i in range(200_000)], dtype=object)})
con = duckdb.connect()
def work():
cursor = con.cursor()
while True:
cursor.execute("select count(a), min(a) from frame").fetchall()
for _ in range(4):
threading.Thread(target=work, daemon=True).start()
time.sleep(0.5)
print("done", flush=True)
Run it repeatedly on Python 3.14 with a timeout, because some runs hang:
for i in $(seq 1 100); do timeout 20 python repro.py >/dev/null 2>err.txt; echo $?; done | sort | uniq -c
With duckdb==2.0.0 from PyPI on Linux aarch64, one run at a time, the script above hung at exit in 4 of 100 runs on Python 3.14.7 and in 0 of 50 on Python 3.13.15. With 12 runs in parallel, as in the table above, the crashes appear as well.
OS:
Amazon Linux 2023 (aarch64); also seen on macOS arm64 and Windows amd64 GitHub Actions runners
DuckDB Package Version:
2.0.0
Python Version:
3.14.7 (3.13.15 is not affected)
Full Name:
Rusty Conover
Affiliation:
Query.Farm
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I tested with the latest release.
Did you include all relevant data sets for reproducing the issue?
Not applicable - the reproduction does not require a data set
Did you include all code required to reproduce the issue?
- Yes, I have
Did you include all relevant configuration to reproduce the issue?
- Yes, I have
🤖 Generated with Claude Code
- 主要言語
- Python
- スター
- 194
- フォーク
- 119
- 平均マージ
- 17時間 33分
- マージ済み PR(30日)
- 49
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
duckdb/duckdb-python のほかの issue
-
needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
duckdb/duckdb-python#708 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Type stubs omit the `connection` keyword on module-level `read_json` and `write_csv`対応中かも @tojacob03 が 25 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
duckdb/duckdb-python#627 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
`read_json` accepts a list of paths at runtime but the type stub only allows a single path.対応中かも @aleks-drozy が 83 日前に担当しました。 オープンneeds triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
duckdb/duckdb-python#576 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Missing ROW_GROUPS_PER_FILE argument in write_parquet function対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンneeds triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
duckdb/duckdb-python#386 ·
メンテナーはふだん 1 日以内に返信
-
needs triage
duckdb/duckdb-python#716 ·
メンテナーはふだん 1 日以内に返信
duckdb/duckdb-python の issue をすべて見る
似ている issue
-
Project submission:オープン
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
slavakurilyak/awesome-ai-agents#845 ·
メンテナーはふだん 1 日以内に返信
-
tests: pin that the atomic writers in utils/paths.py stage the temporary file in the target's directory対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンdifficulty:2 enhancement good first issue
難易度 1/5 1〜3時間 初心者へのやさしさ 92/100
MakazhanAlpamys/Soup#2178 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] dcg.waggr permutation p-values are folded twice, so near-zero scores get the smallest p-valuesオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
scverse/rapids-singlecell#854 ·
メンテナーはふだん 1 日以内に返信
-
Slang input: int8_t4_packed and uint8_t4_packed are copied into CrossGL対応中かも @ninglinLiu が今日担当しました。 オープンarea:frontend backend:slang bug direction:input
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 13 日以内に返信