test: Ignore error message give from python because of PYTHON_GIL - #33795
test: Ignore error message give from python because of PYTHON_GIL#33795kevkevinpal wants to merge 1 commit into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33795. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsNo conflicts as of last run. |
8dd16d9 to
516f87d
Compare
|
As mentioned in the issue, I don't see the problem that free threading solves for us. In fact, it is likely going to cause more issues that are not worth it to debug nor fix. Free threading could make sense if there is a heavy multithreaded production workload. However, I don't see this in the functional test, which are single-threaded, or at most double threaded? I'd say we should just require the GIL for all Python code. I can't see Python removing the GIL any time soon without controversy. And if they do, workarounds such as this one won't work and are not needed anyway. |
|
I'd be interested to know if the test passes with GIL force-disabled with In any case, I think it would probably be best just to suppress this warning with with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
message=r"The global interpreter lock .* capnp\.lib\.capnp",
category=RuntimeWarning,
module=r"importlib\._bootstrap",
)
import capnpI think it only makes sense to skip the test if |
516f87d to
4ab4fd7
Compare
|
I went with the suggestion to suppress the warning here 4ab4fd7 Not sure how verbose you want me to be with the |
4ab4fd7 to
136dfde
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
| with warnings.catch_warnings(): | ||
| warnings.filterwarnings( | ||
| "ignore", | ||
| message=r"The global interpreter lock .*", | ||
| category=RuntimeWarning, | ||
| module=r"importlib\._bootstrap", | ||
| ) |
There was a problem hiding this comment.
not sure. This seems to go in the wrong direction. It disables a legit? warning without any reason why disabling it would be safe or is even desirable. See #33582 (comment) and #33795 (comment)
The correct fix would be to just require the GIL
There was a problem hiding this comment.
The correct fix would be to just require the GIL
That's right, the text of the warning (from #33582) states "The global interpreter lock (GIL) has been enabled to load module 'capnp.lib.capnp'", so my understanding is when this test is run, the GIL is enabled and the test succeeds, except there is a spurious warning at the end which causes the test runner to fail.
So to me it seems like a good fix is disable the warning, since we know about it and are expecting it, and there not a good reason make the test fail after it succeeds. But if you have a different fix in mind, I could imagine it making sense and would be curious to know the details.
Seperately in 136dfde1c2284e30ecb1dfb35520f93878ec7335, I do think it would be good to deduplicate the code that detects the warning, maybe by adding a utility function, or maybe just by returning a reference to the capnp module after it is imported once.
There was a problem hiding this comment.
The correct fix would be to just require the GIL
That's right, the text of the warning (from #33582) states "The global interpreter lock (GIL) has been enabled to load module 'capnp.lib.capnp'", so my understanding is when this test is run, the GIL is enabled and the test succeeds, except there is a spurious warning at the end which causes the test runner to fail.
Ok, this was not clear at all to me. It would be good to at least document, so that code-readers don't have to git blame to find the commit id, then look up the pull request, then read the pull request comments, then go back to the original issue, then read the original issue, then decide that the warning was ok to suppress.
But if you have a different fix in mind, I could imagine it making sense and would be curious to know the details.
I am thinking about setting PYTHON_GIL=1 in the test runner, so that tests pick it up. Also, the test framework could be adjusted to reject PYTHON_GIL=0 early in startup, to guard against manual runs outside the test runner.
There was a problem hiding this comment.
re: #33795 (comment)
I am thinking about setting
PYTHON_GIL=1in the test runner, so that tests pick it up.
This seems like a reasonable alternative, but if we take this approach I hope we only do it selectively for the tests which need it.
I understand we may have some tests which aren't thread safe (though hopefully not too many if most tests are single-threaded) and it may be a lot easier to set PYTHON_GIL=1 than to fix them.
But it could be a bad situation if in a few years PYTHON_GIL=1 becomes deprecated or untenable to use, and newer tests at that point wind up having the same thread safety bugs as old tests. It would seem best not to enable PYTHON_GIL=1 where it's not actually needed and develop a stronger dependency on it.
ryanofsky
left a comment
There was a problem hiding this comment.
Code review 136dfde1c2284e30ecb1dfb35520f93878ec7335. I think this is a good approach, and that suppressing the warning is the most direct fix for the test failure that avoids reducing test coverage. I left some suggestions below for avoiding code duplication and documenting the workaround better. Also think the PR title and description could be updated since the test is no longer skipped.
| with warnings.catch_warnings(): | ||
| warnings.filterwarnings( | ||
| "ignore", | ||
| message=r"The global interpreter lock .*", | ||
| category=RuntimeWarning, | ||
| module=r"importlib\._bootstrap", | ||
| ) |
There was a problem hiding this comment.
re: #33795 (comment)
I am thinking about setting
PYTHON_GIL=1in the test runner, so that tests pick it up.
This seems like a reasonable alternative, but if we take this approach I hope we only do it selectively for the tests which need it.
I understand we may have some tests which aren't thread safe (though hopefully not too many if most tests are single-threaded) and it may be a lot easier to set PYTHON_GIL=1 than to fix them.
But it could be a bad situation if in a few years PYTHON_GIL=1 becomes deprecated or untenable to use, and newer tests at that point wind up having the same thread safety bugs as old tests. It would seem best not to enable PYTHON_GIL=1 where it's not actually needed and develop a stronger dependency on it.
136dfde to
d848b8d
Compare
|
Would it make sense to add a TODO to remove the warning suppression once GIL is supported in the capnp library? |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
1f2f5b8 to
e075fe7
Compare
e075fe7 to
5b7778c
Compare
|
Added a TODO to remove the warning suppression once |
5b7778c to
ef268ee
Compare
There was a problem hiding this comment.
Code review ACK ef268ee288c04a31dd802c4bb729a0c2e6e64786. IMO, this is the most direct fix possible for #33582: Python is warning about something which we don't care about, so we disable the warning. I think this is a better fix than skipping the test or forcing the GIL to be enabled long-term. It can be reverted later if pycapnp is updated to work without the GIL, or if we decide we do want to turn on the GIL explicitly.
ef268ee to
eedea77
Compare
|
Rebased this PR to eedea77 |
|
@maflcko do you want to give this another look? |
|
Yeah, I think I am not affected and I am not sure who is even affected. No objection, but I think the only ones affected are the ones shooting themselves in the foot: #33582 (comment) Also, I don't really understand the pull description. It doesn't list any error message or warning related to the changes here. Instead it lists an unrelated warning and a passing test, the meaning of which is unclear: ~0 on this, but I don't mind other people taking a look here |
|
Thanks for the review!
Sorry about that, I updated the description, hopefully it makes more sense now for new readers |
|
Approach NACK. Not a blocker, but I don't like the direction of this change, as already explained several times. We already have more than enough intermittent issues to deal with right now. Somehow pretending that we support no-gil, want to debug issues in it, have them filed, tracked, and fixed, seems the wrong direction. There isn't any benefit in doing so right now. In fact, there are immediate downsides (#33582 (comment), #33795 (comment)). The only benefit seems to be in a made-up future where gil is deprecated (#33795 (comment)) Absent any indication of this happening, it doesn't seem worth it to spend time on this. And by the time it does happen, hopefully there will be tooling around, like a tsan for python to deal/debug it. The correct fix would be to temporarily force |
|
Thanks for the review!
That makes sense. I opened a PR doing this #34869 I can keep this PR open for now if there is objection to default using |
|
Closing this PR because this was merged instead #34869 Feel free to reopen if we ever want to include a change like this |
Description
I was able to reproduce this issue #33582
Currently, if a user is running Python version
3.14.0tthey will get this error message and the test suite will halt.Instead of halting, we should ignore and suppress the warning message because, regardless of
PYTHON_GILbeing set, our tests should pass.In this change, we are avoiding setting
PYTHON_GIL=1in case it is deprecated in the future, so that newer tests would avoid having thread safety bugs. It makes sense not to have our test suite depend onPYTHON_GIL=1Before and after applying this patch
Before: Warning message when using Python version
3.14.0tandPYTHON_GILunset on master branchAfter: Applying this patch, when
PYTHON_GILis0or1or not set