-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
C API: PyGC_Disable()
not respected
#116604
Labels
type-bug
An unexpected behavior, bug, or error
Comments
@wjakob can you confirm if this affects 3.12? |
@pablogsal Confirmed. I am on 3.12.2. PS: I realized that my original bug description had a |
I will investigate this shortly but if it affects 3.12 I understand exactly what is happening 👍 |
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Mar 11, 2024
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Mar 11, 2024
Signed-off-by: Pablo Galindo <[email protected]>
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Mar 11, 2024
Signed-off-by: Pablo Galindo <[email protected]>
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Mar 11, 2024
Signed-off-by: Pablo Galindo <[email protected]>
pablogsal
added a commit
that referenced
this issue
Mar 12, 2024
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Mar 12, 2024
…y_RunGC (pythonGH-116628) (cherry picked from commit 02918aa) Co-authored-by: Pablo Galindo Salgado <[email protected]>
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Mar 12, 2024
The free-threaded GC only does full collections, so it uses a threshold that is a maximum of a fixed value (default 2000) and proportional to the number of live objects. If there were many live objects after the previous collection, then the threshold may be larger than 10,000 causing `test_indirect_calls_with_gc_disabled` to fail. This manually sets the threshold to `(1000, 0, 0)` for the test. The `0` disables the proprtional scaling.
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Mar 12, 2024
The free-threaded GC only does full collections, so it uses a threshold that is a maximum of a fixed value (default 2000) and proportional to the number of live objects. If there were many live objects after the previous collection, then the threshold may be larger than 10,000 causing `test_indirect_calls_with_gc_disabled` to fail. This manually sets the threshold to `(1000, 0, 0)` for the test. The `0` disables the proportional scaling.
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Mar 12, 2024
…readed build This isn't strictly necessary because the implementation of `gc_should_collect` already checks `gcstate->enabled` in the free-threaded build, but it seems like a good idea until the common pieces of gc.c and gc_free_threading.c are refactored out.
colesbury
added a commit
that referenced
this issue
Mar 12, 2024
… build (#116663) This isn't strictly necessary because the implementation of `gc_should_collect` already checks `gcstate->enabled` in the free-threaded build, but it seems like a good idea until the common pieces of gc.c and gc_free_threading.c are refactored out.
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Mar 12, 2024
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Mar 12, 2024
pablogsal
pushed a commit
that referenced
this issue
Mar 13, 2024
The free-threaded GC only does full collections, so it uses a threshold that is a maximum of a fixed value (default 2000) and proportional to the number of live objects. If there were many live objects after the previous collection, then the threshold may be larger than 10,000 causing `test_indirect_calls_with_gc_disabled` to fail. This manually sets the threshold to `(1000, 0, 0)` for the test. The `0` disables the proportional scaling.
vstinner
pushed a commit
to vstinner/cpython
that referenced
this issue
Mar 20, 2024
The free-threaded GC only does full collections, so it uses a threshold that is a maximum of a fixed value (default 2000) and proportional to the number of live objects. If there were many live objects after the previous collection, then the threshold may be larger than 10,000 causing `test_indirect_calls_with_gc_disabled` to fail. This manually sets the threshold to `(1000, 0, 0)` for the test. The `0` disables the proportional scaling.
adorilson
pushed a commit
to adorilson/cpython
that referenced
this issue
Mar 25, 2024
adorilson
pushed a commit
to adorilson/cpython
that referenced
this issue
Mar 25, 2024
…readed build (python#116663) This isn't strictly necessary because the implementation of `gc_should_collect` already checks `gcstate->enabled` in the free-threaded build, but it seems like a good idea until the common pieces of gc.c and gc_free_threading.c are refactored out.
adorilson
pushed a commit
to adorilson/cpython
that referenced
this issue
Mar 25, 2024
The free-threaded GC only does full collections, so it uses a threshold that is a maximum of a fixed value (default 2000) and proportional to the number of live objects. If there were many live objects after the previous collection, then the threshold may be larger than 10,000 causing `test_indirect_calls_with_gc_disabled` to fail. This manually sets the threshold to `(1000, 0, 0)` for the test. The `0` disables the proportional scaling.
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this issue
Apr 17, 2024
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this issue
Apr 17, 2024
…readed build (python#116663) This isn't strictly necessary because the implementation of `gc_should_collect` already checks `gcstate->enabled` in the free-threaded build, but it seems like a good idea until the common pieces of gc.c and gc_free_threading.c are refactored out.
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this issue
Apr 17, 2024
The free-threaded GC only does full collections, so it uses a threshold that is a maximum of a fixed value (default 2000) and proportional to the number of live objects. If there were many live objects after the previous collection, then the threshold may be larger than 10,000 causing `test_indirect_calls_with_gc_disabled` to fail. This manually sets the threshold to `(1000, 0, 0)` for the test. The `0` disables the proportional scaling.
@pablogsal Should this issue be closed? |
Yep |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
Bug description:
The Python C API provides the function PyGC_Disable() to temporarily disable garbage collection. Calling it causes
PyGC_Collect()
to become a no-op. So far so good.Unfortunately, CPython >= 3.12 no longer respects this flag beyond direct calls to
PyGC_Collect()
. Let's consider, for example, the operationPyErr_CheckSignals()
at line 1773. This calls_Py_RunGC
, which ignores the GCenabled
flag. And this indeed happens! In fact, I just spent quite a bit of time debugging an issue where the GC was supposed to be disabled for a brief moment, and yet it runs on Python 3.12. (Whether disabling the GC for a brief period of time is a good design pattern is another discussion. I would like to steer the discussion away from this and focus on documented API behavior.)The
PyErr_CheckSignals()
function is called from 135 locations in the CPython codebase including very common ones likePyObject_Str()
, so making any fixes in callers of this API does not look feasible.The flag-ignoring
_Py_RunGC()
function is only called by two places: besides the mentionedPyErr_CheckSignals()
, there is also_Py_HandlePending()
inPython/ceval_gil.c
.To restore the documented behavior, I see three options:
_Py_RunGC()
could be modified to exit immediately if theenabled
flag is set to zero._Py_HandlePending()
andPyErr_CheckSignals()
could be modified to checkPyGC_IsEnabled()
before calling_Py_RunGC()
._PY_GC_SCHEDULED_BIT
, and that causes the implementation to enter_Py_RunGC()
. I'm not really sure about how that works, but perhaps this flag could be cleared inPyGC_Disable()
, and Python could then avoid setting the flag.(Tagging @pablogsal and @swtaarrs, who commited changes to the relevant code.)
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
gcstate->enabled
in _Py_RunGC in free-threaded build #116663The text was updated successfully, but these errors were encountered: