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:

from concurrent import interpreters

def f():
    import time
    time.sleep(100)

if __name__ == '__main__':
    interp = interpreters.create()
    print('press CTRL^C twice:')
    t = interp.call_in_thread(f)
    t.join()
Assertion failed: !_PyInterpreterState_IsRunningMain(interp), file C:\rc\Python\pylifecycle.c, line 2516

The same assert can be triggered without keystrokes:

import threading
from concurrent import interpreters

interp = 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

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions