Skip to content

Add subinterpreter support#279

Open
scopreon wants to merge 6 commits intobloomberg:mainfrom
scopreon:add_subinterpreter_support
Open

Add subinterpreter support#279
scopreon wants to merge 6 commits intobloomberg:mainfrom
scopreon:add_subinterpreter_support

Conversation

@scopreon
Copy link
Contributor

@scopreon scopreon commented Feb 22, 2026

Issue number of the reported bug or feature request: #59

Describe your changes
This PR adds simple subinterpreter support to pystack. It preserves all original functionality but does it a few more times by traversing the interpreter linked list. It only supports pure python stacks currently.

Added a new component TracebackPrinter which should help with printing in future. Additional configuration for the printer can be added in future.

Few changes in version.h/cpp.

First contribution so maybe missed something.

Testing performed
Added tests for TracebackPrinter. Added additional end-to-end test for subinterpreters support using the new concurrent 3.14 functionality.

Additional context
Example output

root@875d1afe36dd:/workspaces/pystack# pystack remote 86996
Interpreter-3
  Traceback for thread 87005 (Thread-3 (exec)) [] (most recent call last):
      (Python) File "<script>", line 5, in <module>
  
Interpreter-2
  Traceback for thread 87004 (Thread-2 (exec)) [] (most recent call last):
      (Python) File "<script>", line 5, in <module>
  
Interpreter-1
  Traceback for thread 87003 (Thread-1 (exec)) [] (most recent call last):
      (Python) File "<script>", line 5, in <module>
  
Interpreter-0 (main)
  Traceback for thread 87005 (Thread-3 (exec)) [] (most recent call last):
      (Python) File "/usr/lib/python3.14/threading.py", line 1044, in _bootstrap
          self._bootstrap_inner()
      (Python) File "/usr/lib/python3.14/threading.py", line 1082, in _bootstrap_inner
          self._context.run(self.run)
      (Python) File "/usr/lib/python3.14/threading.py", line 1024, in run
          self._target(*self._args, **self._kwargs)
      (Python) File "/usr/lib/python3.14/concurrent/interpreters/__init__.py", line 215, in exec
          excinfo = _interpreters.exec(self._id, code, restrict=True)
  
  Traceback for thread 87004 (Thread-2 (exec)) [] (most recent call last):
      (Python) File "/usr/lib/python3.14/threading.py", line 1044, in _bootstrap
          self._bootstrap_inner()
      (Python) File "/usr/lib/python3.14/threading.py", line 1082, in _bootstrap_inner
          self._context.run(self.run)
      (Python) File "/usr/lib/python3.14/threading.py", line 1024, in run
          self._target(*self._args, **self._kwargs)
      (Python) File "/usr/lib/python3.14/concurrent/interpreters/__init__.py", line 215, in exec
          excinfo = _interpreters.exec(self._id, code, restrict=True)
  
  Traceback for thread 87003 (Thread-1 (exec)) [] (most recent call last):
      (Python) File "/usr/lib/python3.14/threading.py", line 1044, in _bootstrap
          self._bootstrap_inner()
      (Python) File "/usr/lib/python3.14/threading.py", line 1082, in _bootstrap_inner
          self._context.run(self.run)
      (Python) File "/usr/lib/python3.14/threading.py", line 1024, in run
          self._target(*self._args, **self._kwargs)
      (Python) File "/usr/lib/python3.14/concurrent/interpreters/__init__.py", line 215, in exec
          excinfo = _interpreters.exec(self._id, code, restrict=True)
  
  Traceback for thread 86996 (python3.14) [] (most recent call last):
      (Python) File "/workspaces/pystack/test_file_multiple_interps.py", line 28, in <module>
          print("Main interpreter sleeping forever...")

@codecov-commenter
Copy link

codecov-commenter commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 78.82883% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.13%. Comparing base (58dcac6) to head (6f9df58).

Files with missing lines Patch % Lines
src/pystack/_pystack/pythread.cpp 32.55% 29 Missing ⚠️
tests/integration/test_subinterpreters.py 48.38% 16 Missing ⚠️
src/pystack/_pystack/interpreter.cpp 88.88% 1 Missing ⚠️
src/pystack/_pystack/process.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #279      +/-   ##
==========================================
+ Coverage   83.03%   83.13%   +0.09%     
==========================================
  Files          48       50       +2     
  Lines        6242     6396     +154     
  Branches      480      489       +9     
==========================================
+ Hits         5183     5317     +134     
- Misses       1059     1079      +20     
Flag Coverage Δ
cpp 83.13% <78.82%> (+0.09%) ⬆️
python_and_cython 83.13% <78.82%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants