python / python/cpython

`concurrent.interpreters.Interpreter.exec` propagate `SyntaxError`

Open
#139,324 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.14 3.15 docs topic-subinterpreters
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

Hi,

I am testing the concurrent.interpreters feature from Python 3.14rc3 (the latest current rc).

The subinterpreter seems to behave in a surprising way when encountering syntax errors. For example, in the following code:

from concurrent import interpreters

interpr = interpreters.create()

def exec_catching_errors(code: str) -> None:
    try:
        interpr.exec(code)
    except interpreters.ExecutionFailed as e:
        print(f"There was an error: {e}")
    print("The function ends")


exec_catching_errors("print(1/0)")
exec_catching_errors("print 1")  # this is the surprising line

# the whole script dies with an uncaught SyntaxError
  • trying to execute print(1/0) causes an interpreters.ExecutionFailed that correctly wraps a ZeroDivisionError.
  • trying to execute print 1 causes a bare SyntaxError, whereas I would have expected a subclass of interpreters.InterpreterError wrapping the SyntaxError.

Is this intended behaviour, a bug, or something that simply needs to be better documented?

Thanks

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the implementation of concurrent.interpreters.Interpreter.exec and reproduce the two code snippets from the report on Python 3.14. Determine the intended handling of SyntaxError versus ExecutionFailed, then add or update focused tests so the behavior is explicit and consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.