python / cpython

The Python programming language
https://www.python.org
Other
63.36k stars 30.35k forks source link

"Windows fatal Exception: access violation" while testing 3.13.0b1 free-threading build (related to tkinter ?) #118973

Open stonebig opened 5 months ago

stonebig commented 5 months ago

Crash report

What happened?

doing pytest on my github repository "sqlite-bro" , with Python-3.13.0b1 augmented per:

I get a crash

```text C:\Users\stonebig\Documents\GitHub\sqlite_bro>pytest ====================================================================== test session starts ======================================================================= platform win32 -- Python 3.13.0b1, pytest-8.2.0, pluggy-1.5.0 rootdir: C:\Users\stonebig\Documents\GitHub\sqlite_bro configfile: pyproject.toml collecting ... Windows fatal exception: access violation Current thread 0x00006b84 (most recent call first): File "", line 488 in _call_with_frames_removed File "", line 1315 in create_module File "", line 813 in module_from_spec File "", line 921 in _load_unlocked File "", line 1331 in _find_and_load_unlocked File "", line 1360 in _find_and_load File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\tkinter\__init__.py", line 38 in File "", line 488 in _call_with_frames_removed File "", line 1021 in exec_module File "", line 935 in _load_unlocked File "", line 1331 in _find_and_load_unlocked File "", line 1360 in _find_and_load File "C:\Users\stonebig\Documents\GitHub\sqlite_bro\sqlite_bro\sqlite_bro.py", line 23 in File "", line 488 in _call_with_frames_removed File "", line 1021 in exec_module File "", line 935 in _load_unlocked File "", line 1331 in _find_and_load_unlocked File "", line 1360 in _find_and_load File "", line 488 in _call_with_frames_removed File "", line 1415 in _handle_fromlist File "C:\Users\stonebig\Documents\GitHub\sqlite_bro\sqlite_bro\tests\test_general.py", line 7 in File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\assertion\rewrite.py", line 178 in exec_module File "", line 935 in _load_unlocked File "", line 1331 in _find_and_load_unlocked File "", line 1360 in _find_and_load File "", line 1387 in _gcd_import File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\importlib\__init__.py", line 88 in import_module File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\pathlib.py", line 591 in import_path File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\python.py", line 487 in importtestmodule File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\python.py", line 540 in _getobj File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\python.py", line 282 in obj File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\python.py", line 556 in _register_setup_module_fixture File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\python.py", line 543 in collect File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\runner.py", line 389 in collect File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\runner.py", line 341 in from_call File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\runner.py", line 391 in pytest_make_collect_report File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\pluggy\_callers.py", line 103 in _multicall File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\pluggy\_manager.py", line 120 in _hookexec File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\pluggy\_hooks.py", line 513 in __call__ File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\runner.py", line 565 in collect_one_node File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\main.py", line 837 in _collect_one_node File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\main.py", line 974 in genitems File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\main.py", line 979 in genitems File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\main.py", line 979 in genitems File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\main.py", line 979 in genitems File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\main.py", line 811 in perform_collect File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\main.py", line 349 in pytest_collection File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\pluggy\_callers.py", line 103 in _multicall File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\pluggy\_manager.py", line 120 in _hookexec File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\pluggy\_hooks.py", line 513 in __call__ File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\main.py", line 338 in _main File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\main.py", line 285 in wrap_session File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\main.py", line 332 in pytest_cmdline_main File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\pluggy\_callers.py", line 103 in _multicall File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\pluggy\_manager.py", line 120 in _hookexec File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\pluggy\_hooks.py", line 513 in __call__ File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\config\__init__.py", line 178 in main File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Lib\site-packages\_pytest\config\__init__.py", line 206 in console_main File "C:...\WPy64-31300b1\python-3.13.0b1.amd64\Scripts\pytest.exe\__main__.py", line 7 in File "", line 88 in _run_code File "", line 198 in _run_module_as_main ```

on 3.13.0b1 patched the same but not Free-threading all seems ok

```text ================================================= test session starts ================================================= platform win32 -- Python 3.13.0b1, pytest-8.2.0, pluggy-1.5.0 rootdir: C:\Users\stonebig\Documents\GitHub\sqlite_bro configfile: pyproject.toml collected 3 items sqlite_bro\tests\test_general.py ... [100%] ================================================== 3 passed in 0.76s ================================================== ```

I did that test because IDLE doesn't want to start and doesn't say why. Package set used:

Package         Version      Summary
_______________ ____________ ______________________________________________________________________
build           1.1.1        A simple, correct Python build frontend
colorama        0.4.6        Cross-platform colored terminal text.
iniconfig       2.0.0        brain-dead simple config-ini parsing
packaging       23.2         Core utilities for Python packages
pip             24.0         The PyPA recommended tool for installing Python packages.
pluggy          1.5.0        plugin and hook calling mechanisms for python
pyproject-hooks 1.0.0        Wrappers to call pyproject.toml-based build backend hooks.
pytest          8.2.0        pytest: simple powerful testing with Python
setuptools      69.2.0       Easily download, build, install, upgrade, and uninstall Python package
sqlite-bro      0.13.1       a graphic SQLite Client in 1 Python file
wheel           0.43.0       A built-package format for Python
winpython       8.0.20240512 WinPython distribution tools, including WPPM

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Output from running 'python -VV' on the command line:

Python 3.13.0b1 (tags/v3.13.0b1:2268289, May 8 2024, 12:31:50) [MSC v.1938 64 bit (AMD64)]

stonebig commented 5 months ago

maybe related to this still missing piece ? https://github.com/colesbury/nogil-3.12/commit/78825e0508 image

KRRT7 commented 4 months ago

simply importing

from tkinter.filedialog import askopenfile

crashes 3.13t for me, which is imported in the sqlite_bro project. hope this helps narrow down the issue.

stonebig commented 4 months ago

By the look of current early state of free-threading, we may assume the tkinter/free-threading is rather a 2025 question, with uncertain fate.

python-zhong commented 4 months ago

I tried to use WinDbg to debug it, and found:

screenshot

mishaturnbull commented 4 weeks ago

+1 for this happening on Windows only, version 3.13.0 (non-beta, release day build). I see exactly the same error as @python-zhong when running python3.13t.exe -m tkinter under WinDbg (no pytest involved). The tkinter test dialog launches and operates correctly when not in free-threading mode (GIL enabled) on the same machine. I tested the same command on a Debian platform (compiled the same 3.13.0 tag), and it worked flawlessly in free-threaded mode. Don't have a mac to test on, unfortunately.

Platform details:

colesbury commented 4 weeks ago

@zooba The official Windows installer (with free-threading binaries) only includes a Python313\DLLs\_tkinter.pyd. There's no _tkinter.cp313t-win_amd64, so importing tkinter in py -3.13t crashes as it tries to load an incompatible extension.

Do you know why that's happening?

terryjreedy commented 4 weeks ago

As noted in https://github.com/python/cpython/issues/125179#issuecomment-2402681892, I have run tkinter and IDLE on debug + free-threading builds since last March. But I never tried the installers. Of course, PCbuild/amd64 has a full set of _xyz_d.cp314t-win_amd64.ext files. I'm sorry I did not notice this issue before.

mishaturnbull commented 4 weeks ago

Yep, figured out the free-threading build on the same Windows box (sorry about the delay, Visual Studio noob), and when compiled locally tkinter operates flawlessly on free-threading.

Admittedly, I've just compiled Cpython for the first time yesterday -- but, if this is simple to fix, I'd be happy to submit a PR for it if that would help?