Skip to content

Assertion failure when interrupting active threads for subinterpreters#137295

@neonene

Description

@neonene

Crash report

What happened?

The following code runs a subinterpreter in a new non-daemon thread, where CTRL+C+C interruption causes an assertion failure on debug builds:

fromconcurrentimportinterpretersdeff(): importtimetime.sleep(100) if__name__=='__main__': interp=interpreters.create() print('press CTRL^C twice:') t=interp.call_in_thread(f) t.join()
Assertionfailed: !_PyInterpreterState_IsRunningMain(interp), fileC:\rc\Python\pylifecycle.c, line2516

The same assert can be triggered without keystrokes:

importthreadingfromconcurrentimportinterpretersinterp=interpreters.create() t=threading.Thread(target=interp.exec, daemon=True, args=('import time; time.sleep(3)',)) t.start()

cc @ericsnowcurrently

CPython versions tested on:

3.14.0rc1, CPython main branch: 2a87af0

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-subinterpreterstype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions