-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-135410: Fix test_memoryio
refleak buildbots
#135430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
!buildbot nogil refleak |
🤖 New build scheduled with the buildbot fleet by @ZeroIntensity for commit b6f2011 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135430%2Fmerge The command will test the builders whose names match following regular expression: The builders matched are:
|
Sorry for challenging your changes recently, but why don’t we ensure consistent behavior between the pure Python and C versions? |
Please hold on: "IMO this change was merged too quickly and I suggest to revert it." #135412 (comment) |
The pure Python will not crash the interpreter while the C implementation can crash and the easiest way to fix the latter is to add critical section. We are trying to fix thread safety in regard to avoid being able to crash the interpreter. Another somewhat related is #130095 where abc's pure Python implementation is not thread safe but it cannot crash the interp so we aren't actively fixing that, rather skipping the pure python tests of it. As for performance, critical sections are optimized for case where single thread acquires it so it is minimal, trying to write to same StringIO object would perform worse but that's not something users should do or we should try to optimize for. |
No worries, I don't take it personally :)
That's effectively what I was trying to do. #135412 was trying to solely fix the segfault. Unfortunately, the only easy way to do that is by slapping a critical section onto I agree with Kumar that this probably won't be noticeable for single-threaded code. I pushed back on locking |
I know pure Python code doesn’t crash the interpreter, but that’s not the point. The problem is that it behaves differently from the C implementation: the Python version is not thread-safe, while the C version is. We should aim for consistent behavior between them and consider what we’ve done so far toward that goal. That’s why I suggested we revisit our approach to make the behavior consistent between the pure Python and C implementations. |
Closing now that the original change has been reverted. |
The problem is that we were testing both
_pyio.StringIO
and_io.StringIO
. The former, in_pyio
, isn't really thread-safe (but it doesn't crash, and that's what we care about). I'm not sure why it only revealed itself on the refleak buildbots, but it's probably something about the threads being slower.Anyways, I'm fixing this by only testing the C implementation of
StringIO
. Making the Python version thread-safe is a separate project that we shouldn't deal with here. I also changed theassertIsNone
to anif
that actually raises the exception, so we get a better traceback when dealing with failures.StringIO
methods in threads on free-threading debug build #135410