Replies: 1 comment 1 reply
-
That's a good question and the answer will change as the project progresses. For now, the focus is on getting things to work, and less about trying to root out all the long tail bugs. Reading code to look for shared state is surprisingly effective. ThreadSanitizer is sometimes useful. So is the debug allocator. Running lots of copies to find deadlocks and crashes helps. As the project progresses, rooting out the hard-to-detect issues will become more important. I expect that will involve more automated testing (including under TSan). For example, we could take a project's test suite and run individual tests cases concurrently from multiple threads. That won't work for all projects, but we could filter it to test cases that succeed when run that way with the GIL enabled.
I think it makes sense for Python to default to GIL-on (at least for a few releases). For example, you have to run with I'm ambivalent about tagging extensions. It might make sense. It is possible to fall-back to enabling the GIL when importing a non-tagged extension. I'm worried that the tagging system may introduce unnecessary complexity. Alternatively, extension authors can programmatically check if the GIL is enabled and issue a warning/error/force-enable the GIL. I don't think it makes sense to lock/unlock around every function call. As you say, that's not sufficient to provide compatibility. Since you've developed a number of Python extensions, a few questions: Would running Python without the GIL be useful with any of your packages? Would you be interested in reviewing patches to make one (or more) of the packages thread-safe without the GIL? |
Beta Was this translation helpful? Give feedback.
-
The document says "In my experience, it was not too difficult to ensure that the dozens of packages used by a given project work without the GIL; I’d expect this to be easier with community involvement." How are you verifying that? In my experience, thread safety issues are really hard to detect, often only showing up under heavy load and on some machines and not others, and race detection tools like those in valgrind can be fairly hit-or-miss (and normally requires
PYTHONMALLOC=malloc
, which I'm guessing might be incompatible with the mimalloc change?).While I don't have a clear picture of whether this problem only affects extensions or potentially all Python code, it seems significantly more difficult to verify that a package is nogil-safe than it was to convert from Python 2 to Python 3 (where 2to3/futurize/modernize would do most of the work, and where failures were generally predictable and obvious given good code coverage), and after 10 years there was still a lot of Python 2 code around. I don't want to knock what you've done (making single-threaded code faster is seriously impressive), but I don't think you should under-estimate the cost of breaking existing code.
Would it make sense for extensions to have to assert (through some new API) that they're no-gil ready, with the default being to assume that they aren't? There are a number of options for what to do when importing some extension when running in nogil mode:
Beta Was this translation helpful? Give feedback.
All reactions