Release GIL around blocking Win32 API calls in native functions#2732
Release GIL around blocking Win32 API calls in native functions#2732mhammond merged 3 commits intomhammond:mainfrom
Conversation
62ee1e1 to
666afbb
Compare
|
|
||
| err = NetUserEnum(szServer, level, filter, &buf, dwPrefLen, &numRead, &totalEntries, &resumeHandle); | ||
| if (err != 0 && err != ERROR_MORE_DATA) { | ||
| Py_BEGIN_ALLOW_THREADS err = |
There was a problem hiding this comment.
Thanks! I see how you copied the existing style, but sadly that "style" came from an erroneous auto-format some years ago, and I'm trying to fix them as we touch them. Could you please change these to taking a semi-colon and newlines after the macros? eg, like this code
There was a problem hiding this comment.
There's an option to handle this in clang-format
But adding a trailing ; also works since an empty statement after a brace still results in correct code.
Pros&cons can be discussed on that PR. For here it's sufficient to add ;
…o longer locking the GIL
…L reacquire can overwrite it
|
Fixed formatting, added #2731 to the list of calls changed and updated error handling a little bit. The 3.13, arm64 failure I think is just a test flake not related to this change. |
Yeah that's #2203 |
We noticed in our project that several Win32 API calls were blocking the main thread for 100ms–2s+ each, preventing our asyncio event loop from making progress. After investigation, we found that a number of hand-written native functions call Win32 APIs without releasing the GIL. None of these functions access Python objects during the syscall, so holding the GIL is probably unnecessary.