-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Crash after error in PickleBuffer #122306
Comments
|
Try: import pickle
import atexit
m = memoryview(b"foobar")[::2]
pb = pickle.PickleBuffer(m)
def p(): pb.raw()
atexit.register(m.bit_count) |
|
Better: import pickle
m = memoryview(b"foobar")[::2]
pb = pickle.PickleBuffer(m)
def p(): m.bit_length()
m.invalid |
|
The following analysis report will explain the bug by inserting comments into the log. Main Causes
NextI'm trying to find a method fix this this days. Bug reproduction(tested on mainline)import gc, pickle
mv = memoryview(b"test")
error = None
def func():
try:
pb = pickle.PickleBuffer(mv)
raise Exception("test")
except Exception as e:
# Ensure `error` references the exception
error = e
finally:
print(f"pb:{pb}\nmv:{mv}")
# Cyclic References Explanation:
# An exception creates a traceback object referencing the frame.
# The frame references local variables (`error`, `pb`).
# The exception object references the traceback.
# The `error` variable references the exception.
func()
del mv
gc.collect() # Crash hereGDB Debugging Details |
|
This looks like an example of the hypothetical issue discussed in #77894. The solution was proposed there, but we did not have any reliable way to test it. Now we can, using I'm closing this issue as a duplicate of #77894. |


Crash report
The following script crashes at finalization stage:
Output:
I cannot yet reproduce the crash without
unittest, perhaps it is related to some reference loop.The crash is only happens in 3.12 an newer. In 3.8-3.11 it just raises an exception (
PickleBufferwas added in 3.8).cc @pitrou
Linked PRs
The text was updated successfully, but these errors were encountered: