-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
When creating a sub-interpreter in a new thread (not main), pystack fails to find the TID offset.It seems to be because the interpreter head in the runtime struct does not necessarily point to the main interpreter head. In fact, it looks like it does the opposite by pushing the head interpreter to the tail of the linked list.
https://github.com/python/cpython/blob/4401f23cbf67f286649aebc12633fe3f46ada0d1/Python/pystate.c#L724-L729 and https://github.com/python/cpython/blob/4401f23cbf67f286649aebc12633fe3f46ada0d1/Python/pystate.c#L546-L569
I believe this also means pystack only gets the stack of the latest subinterpreter, not the main one
Expected Behavior
It should not fail in this way.
I have a fix in #279 which navigates the linked list of interpreters (but does a lot more other things)
Steps To Reproduce
import os
import threading
from concurrent import interpreters
pid = os.getpid()
print(f"PID: {pid}", flush=True)
interp = interpreters.create()
code = """\
import time
while True:
time.sleep(1)
"""
t = threading.Thread(target=interp.exec, args=(code,))
t.start()
t.join()
Running pystack on it yields
[saulcoops@mymachine]# pystack remote 740692
ERROR(process_remote): Could not find tid offset in pthread structure
Traceback for thread 740695 (Thread-1 (exec)) [] (most recent call last):
(Python) File "<script>", line 3, in <module>
Pystack Version
1.6.0 but it applies to all
Python Version
3.13
Linux distribution
Red Hat
Anything else?
Python version did not let me choose 3.14