methodcaller
is not thread-safe (or re-entrant)
#127065
Labels
3.13
bugs and security fixes
3.14
new features, bugs and security fixes
topic-free-threading
type-bug
An unexpected behavior, bug, or error
Bug report
EDIT: edited to clarify that the issue is in the C implementation of
operator.methodcaller
.Originally reported by @ngoldbaum in crate-py/rpds#101
Reproducer
Once every 5-10 runs, the program prints:
The problem is that
operator.methodcaller
is not thread-safe because it modifies thevectorcall_args
, which is shared across calls:cpython/Modules/_operator.c
Lines 1646 to 1666 in 0af4ec3
I think this is generally unsafe, not just for free threading. The
vectorcall
args array needs to be valid for the duration of the call, and it's possible formethodcaller
to be called reentrantly or by another thread while the call is still ongoing.Linked PRs
methodcaller
thread-safe in free threading build #127109The text was updated successfully, but these errors were encountered: