-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Segfault/aborts calling readline.set_completer_delims
in threads in a free-threaded build
#126895
Comments
The def _test():
import doctest, difflib
return doctest.testmod(difflib) I think the issue is either with doctest or the imports, not with difflib itself. |
I believe this is due to import pdb
import sys
from threading import Thread
stdin = open("/dev/null")
sys.stdin = stdin
def f():
for x in range(100):
p = pdb.Pdb()
p.reset()
try: # Comment
p.set_trace() # these
except: # lines
pass # out.
p.reset()
p.set_continue()
for x in range(100):
Thread(target=f, args=()).start() So maybe the issue is just that Edit: here's a collection of errors this causes:
|
@gaogaotiantian Is there a plan to make pdb free-threaded friendly or not? if so, how can we help, if not what should we do for this issue? |
I'll wait for Tian's input, but I'm happy to spend a few hours covering pdb in locks if we need to. |
From the code above, the conclusion I can get is Also, |
Does it use some weird frames APIs (e.g. |
The culprit seems to be from threading import Thread
import readline
def f():
for x in range(100):
readline.get_completer_delims()
readline.set_completer_delims(' \t\n`@#%^&*()=+[{]}\\|;:\'",<>?')
readline.set_completer_delims(' \t\n`@#%^&*()=+[{]}\\|;:\'",<>?')
readline.get_completer_delims()
for x in range(100):
Thread(target=f, args=()).start() Seems to fail with the same errors as the original code. |
It's probably the system that's not thread safe in that case. |
The error appears to come from CPython code, line 593 seems to be affecting module global data, right? Lines 578 to 594 in 2313f84
|
I won't be surprised if |
That issue looks a little out of date, but yeah, we're still working on the thread safety. Thanks for your input, Tian! @devdanzin, would you like to author a PR for fixing the global state in |
I wouldn't know how, please take it if you can :) |
Ok, I'm busy with a few other issues right now, so I'll leave this open to someone else for a bit. If nobody decides they want to do it, I'll get to it :) |
I would be a little bit more careful when dealing with |
If it has global state, I doubt the functions themself are thread safe. In that case, we probably should just mark it as needing the GIL. |
difflib._test
in threads in a free-threaded buildreadline.set_completer_delims
in threads in a free-threaded build
Or add |
That wouldn't work for subinterpreters, would it? |
Crash report
What happened?
Calling
difflib._test
in threads in a free-threaded build (withPYTHON_GIL=0
) will result in aborts or segfaults, apparently related to memory issues:Segfault backtrace:
Abort 1 backtrace:
Abort 2 backtrace:
Found using fusil by @vstinner.
CPython versions tested on:
3.13, CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.14.0a1+ experimental free-threading build (heads/main-dirty:612ac283b81, Nov 16 2024, 01:37:56) [GCC 11.4.0]
The text was updated successfully, but these errors were encountered: