GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-111650: Ensure pyconfig.h includes Py_GIL_DISABLED on Windows by zooba · Pull Request #112778 · python/cpython

Conversation

@zooba

@zooba zooba commented Dec 5, 2023 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: Py_GIL_DISABLED not defined in "free-threaded" Windows C-API extensions  #111650

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zooba
pythongh-111650: Ensure pyconfig.h includes PY_GIL_DISABLED on Windows
4feb2ce
@zooba
zooba requested review from a team and FFY00 as code owners December 5, 2023 22:58
@bedevere-app bedevere-app Bot added the awaiting core review label Dec 5, 2023
@bedevere-app bedevere-app Bot mentioned this pull request Dec 5, 2023
Py_GIL_DISABLED not defined in "free-threaded" Windows C-API extensions #111650
Closed
@zooba
zooba requested a review from colesbury December 5, 2023 22:58
colesbury
colesbury reviewed Dec 6, 2023
View reviewed changes
Comment thread PC/pyconfig.h
#define HAVE_X509_VERIFY_PARAM_SET1_HOST 1

/* Define if you want to disable the GIL */
#undef Py_GIL_DISABLED

@colesbury colesbury Dec 6, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to rename the PC/pyconfig.h? It seems like some tools might treat the input template as if it's the true pyconfig.h file.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zooba zooba Dec 6, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not actually a template, it's a totally valid and usable header file. In the default case (for now), Py_GIL_DISABLED is undefined, and we just change that on build if requested.

For editing in an IDE, we need some kind of actual header file available or else all the code assistance tools will fail. Rather than requiring the IDE understand the build directory (which VS can do, but others may not), this allows us to have a default GIL_DISABLED header before building and then the correct one when actually building.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread PCbuild/pyproject.props Resolved

Uh oh!

There was an error while loading. Please reload this page.

zooba added 2 commits December 6, 2023 21:39
@zooba
Fix includes for nogil and tests
0243c40
@zooba
Merge remote-tracking branch 'upstream/main' into pythongh-111650
094ccd9
@zooba
zooba requested review from brettcannon, ericsnowcurrently, ncoghlan, vsajip and warsaw as code owners December 6, 2023 21:39
@zooba
Merge remote-tracking branch 'upstream/main' into pythongh-111650
85811ea
@zooba

zooba commented Dec 7, 2023

Copy link
Copy Markdown
Member Author

The failure in the nogil build is an access violation/segfault (see the end of the build step where we get the real exit code - 0xC0000005), and it doesn't repro on my own machine. I've merged from master again in case it was unlucky and a re-run helps, but otherwise this could be a tricky one to diagnose.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@colesbury

colesbury commented Dec 7, 2023

Copy link
Copy Markdown
Contributor

@zooba, I'll see if I can reproduce it locally

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brettcannon
brettcannon removed their request for review December 7, 2023 18:58
@colesbury

colesbury commented Dec 7, 2023

Copy link
Copy Markdown
Contributor

The files in PC/ are preferring PC/pyconfig.h over the generated one.

zooba reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Dec 7, 2023

Copy link
Copy Markdown
Member Author

Ah, that makes sense. Easily fixed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Dec 7, 2023

Copy link
Copy Markdown
Member Author

Actually, I can't see how that happens unless your build differs from mine. (Side note - we should enable verbose output in CI so that we could see exactly what was happening there... the default output isn't detailed enough.)

What is happening is that the extension modules that are outside the core DLL are getting the unmodified header, because they have independent $(IntDir) directories that don't contain the updated one.

I'll add a new project just to do the header file update, so that way the dependencies/incremental build can work properly and we don't have to repeat the process for every module.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@colesbury

colesbury commented Dec 7, 2023

Copy link
Copy Markdown
Contributor

That's happening too for me (later on in the build), but files like PC\config.c, PC\dl_nt.c, PC\msvcrtmodule.c, PC\winreg.c are pulling the wrong pyconfig.h and they are part of pythoncore.vcxproj.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba
Fix include path for updated pyconfig.h
c33aa01
@zooba

zooba commented Dec 7, 2023

Copy link
Copy Markdown
Member Author

There shouldn't be a case where include "Python.h" -> include "pyconfig.h" searches the source file's directory. It'll look adjacent to Python.h and then start going through INCLUDE, which will have the generated directory earlier than PC/.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba
Expanded output when building
d0b30bb
@zooba
zooba requested review from ezio-melotti and hugovk as code owners December 7, 2023 22:38
@zooba

zooba commented Dec 7, 2023

Copy link
Copy Markdown
Member Author

There shouldn't be a case where include "Python.h" -> include "pyconfig.h" searches the source file's directory.

And yet, /sourceDependencies says otherwise, so I guess the docs are wrong or incomplete here.

I'll hack things together a different way.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zooba added 2 commits December 7, 2023 23:16
@zooba
Move old pyconfig, fix updates
c80c852
@zooba
Fix test
313618b
@zooba

zooba commented Dec 8, 2023

Copy link
Copy Markdown
Member Author

I fixed the test, and found that the crash is because operatormodule.m_index is being set to the same as m_name, which skips assigning the type in PyModuleDef_Init and then null refs during the typecheck in create_builtin (in import.c).

I don't see any obvious reason for the failure, and _operator isn't the first module listed in config.c, but it seems to reliably be that module. I won't get a chance to dig into this for a bit, you might want to look first @colesbury

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@colesbury

colesbury commented Dec 8, 2023

Copy link
Copy Markdown
Contributor

@zooba - I haven't seen the operatormodule.m_index issue either locally or in the GH CI. However, there are a few more #ifndef _MSC_VER guards that need to be removed and an #include "pyconfig.h" needed: colesbury@6158d6e

With that change I'm able to build --disable-gil locally without any compilation warnings and the tests pass.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@colesbury

colesbury commented Dec 8, 2023

Copy link
Copy Markdown
Contributor

However, test_peg_generator still fails because setuptools needs updating. That's only run in buildbots (not GH) and was broken before this PR.

.\PCbuild\amd64\python_d.exe -m test -u all test_peg_generator -v
...
C:\Users\Administrator\cpython\include\Python.h(14): fatal error C1083: Cannot open include file: 'pyconfig.h': No such file or directory
ERROR
...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba
Remove additional guards
6c067b7
@zooba

zooba commented Dec 11, 2023

Copy link
Copy Markdown
Member Author

Yeah, apparently it works today? I see the last push I did also didn't crash. Hopefully it's not uninitialised memory, as that would be annoying to track down.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@colesbury

colesbury commented Dec 11, 2023

Copy link
Copy Markdown
Contributor

!buildbot windows

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Dec 11, 2023

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @colesbury for commit 6c067b7 🤖

The command will test the builders whose names match following regular expression: windows

The builders matched are:

  • AMD64 Windows11 Bigmem PR
  • AMD64 Windows Server 2022 NoGIL PR
  • AMD64 Windows11 Refleaks PR
  • AMD64 Windows10 PR
  • ARM64 Windows Non-Debug PR
  • AMD64 Windows11 Non-Debug PR
  • ARM64 Windows PR
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@colesbury

colesbury commented Dec 11, 2023

Copy link
Copy Markdown
Contributor

It looks like test_peg_generator is failing due to setuptools (and not just on the "nogil" builder as I originally thought). I'm not sure of the best way to fix it. Maybe we can add the intermediates directory to the include path?

cpython/Tools/peg_generator/pegen/build.py

Lines 140 to 145 in 1c5fc02

include_dirs = [
str(MOD_DIR.parent.parent.parent / "Include" / "internal"),
str(MOD_DIR.parent.parent.parent / "Parser"),
str(MOD_DIR.parent.parent.parent / "Parser" / "lexer"),
str(MOD_DIR.parent.parent.parent / "Parser" / "tokenizer"),
]

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Dec 11, 2023

Copy link
Copy Markdown
Member Author

Output directory is the one to add (dirname(sys.executable) or dirname(sys._base_executable) if there's a venv involved unless it's a symlinked venv in which case I think we just lose?)

I do intend to send a PR to setuptools for this, I just haven't yet, and I'd be more inclined to skip the test until that's in. Or if we've actually vendored setuptools, we can just patch our copy for now.1 I'm pretty sure setuptools trusts us enough to merge the change before we merge ours, but I wouldn't blame them if they didn't - it's not their circular dependency.

Footnotes

  1. FTR, this is the kind of scenario that has me -1 on using 3rd-party dependencies in our test suite. ↩

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Dec 11, 2023

Copy link
Copy Markdown
Member Author

unless it's a symlinked venv in which case I think we just lose?

My guess is that this is due to #86179 which I should probably just fix (pretty sure it only needs a realpath call in venv).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Dec 12, 2023

Copy link
Copy Markdown
Member Author

Issue and PR for setuptools are now submitted.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba
Add extra include dir for PEG tests
c74133b
@zooba
zooba requested review from lysnikolaou and pablogsal as code owners December 12, 2023 17:18
@zooba

zooba commented Dec 12, 2023

Copy link
Copy Markdown
Member Author

!buildbot windows

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Dec 12, 2023

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @zooba for commit c74133b 🤖

The command will test the builders whose names match following regular expression: windows

The builders matched are:

  • AMD64 Windows11 Bigmem PR
  • AMD64 Windows Server 2022 NoGIL PR
  • AMD64 Windows11 Refleaks PR
  • AMD64 Windows10 PR
  • ARM64 Windows Non-Debug PR
  • AMD64 Windows11 Non-Debug PR
  • ARM64 Windows PR
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Dec 13, 2023

Copy link
Copy Markdown
Member Author

@colesbury Anything else you think should be handled in this PR? Once this is in (and my other one to fix symlinks and simplify the new sysconfig code) I've got a broader range of build changes to make, so we likely won't have to live with this particular code for long.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

colesbury
colesbury approved these changes Dec 13, 2023
View reviewed changes

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread .github/workflows/reusable-windows.yml
- uses: actions/checkout@v4
- name: Build CPython
run: .\PCbuild\build.bat -e -d -p Win32 ${{ inputs.free-threaded && '--disable-gil' || '' }}
run: .\PCbuild\build.bat -e -d -v -p Win32 ${{ inputs.free-threaded && '--disable-gil' || '' }}

@colesbury colesbury Dec 13, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want to keep this?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zooba zooba Dec 13, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it slows down CI enough to be a problem.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zooba
zooba merged commit 79dad03 into python:main Dec 13, 2023
@bedevere-app bedevere-app Bot removed the awaiting core review label Dec 13, 2023
@zooba
zooba deleted the gh-111650 branch December 13, 2023 15:38
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
@zooba @aisk
pythongh-111650: Ensure pyconfig.h includes Py_GIL_DISABLED on Windows (
aa326a6
pythonGH-112778)
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
@zooba @Glyphack
pythongh-111650: Ensure pyconfig.h includes Py_GIL_DISABLED on Windows (
82fcdcc
pythonGH-112778)
@isuruf isuruf mentioned this pull request Oct 14, 2024
freethreading support conda-forge/psutil-feedstock#78
Merged
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@colesbury colesbury colesbury approved these changes
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ncoghlan ncoghlan Awaiting requested review from ncoghlan ncoghlan is a code owner
@warsaw warsaw Awaiting requested review from warsaw warsaw is a code owner
@vsajip vsajip Awaiting requested review from vsajip vsajip is a code owner
@ezio-melotti ezio-melotti Awaiting requested review from ezio-melotti ezio-melotti is a code owner
@hugovk hugovk Awaiting requested review from hugovk hugovk is a code owner
@pablogsal pablogsal Awaiting requested review from pablogsal pablogsal is a code owner
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@zooba @colesbury @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.