-
Notifications
You must be signed in to change notification settings - Fork 38.8k
test: Ignore error message give from python because of PYTHON_GIL #33795
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
base: master
Are you sure you want to change the base?
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 react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
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. |
maflcko
left a comment
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.
not sure about this
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK ef268ee. 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.
|
🐙 This pull request conflicts with the target branch and needs rebase. |
Description
I was able to reproduce this issue #33582
We should ignore the warning message if
PYTHON_GILis not set, instead of the test being abruptly stoppedWhen
PYTHON_GILis0or1or not set