Skip to content

Resuming python -m asyncio process is not properly handled on Unix-like platforms #139391

@yihong0618

Description

@yihong0618

Bug report

Bug description:

The resumed REPL can't be exited on Unix-like platforms other than through kill:

./python.exe -m asyncio
ctrl + z
fg
# then the terminal boom
>>> 
Traceback (most recent call last):
  File "/Users/hyi/.local/share/uv/python/cpython-3.14.0rc2-macos-aarch64-none/lib/python3.14/_pyrepl/readline.py", line 395, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "/Users/hyi/.local/share/uv/python/cpython-3.14.0rc2-macos-aarch64-none/lib/python3.14/_pyrepl/reader.py", line 752, in readline
    self.restore()
    ~~~~~~~~~~~~^^
  File "/Users/hyi/.local/share/uv/python/cpython-3.14.0rc2-macos-aarch64-none/lib/python3.14/_pyrepl/reader.py", line 608, in restore
    self.console.restore()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/.local/share/uv/python/cpython-3.14.0rc2-macos-aarch64-none/lib/python3.14/_pyrepl/unix_console.py", line 377, in restore
    signal.signal(signal.SIGWINCH, self.old_sigwinch)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hyi/.local/share/uv/python/cpython-3.14.0rc2-macos-aarch64-none/lib/python3.14/signal.py", line 58, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread of the main interpreter
>>> 
Traceback (most recent call last):
  File "/Users/hyi/.local/share/uv/python/cpython-3.14.0rc2-macos-aarch64-none/lib/python3.14/_pyrepl/readline.py", line 395, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "/Users/hyi/.local/share/uv/python/cpython-3.14.0rc2-macos-aarch64-none/lib/python3.14/_pyrepl/reader.py", line 752, in readline
    self.restore()
    ~~~~~~~~~~~~^^
  File "/Users/hyi/.local/share/uv/python/cpython-3.14.0rc2-macos-aarch64-none/lib/python3.14/_pyrepl/reader.py", line 608, in restore
    self.console.restore()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/hyi/.local/share/uv/python/cpython-3.14.0rc2-macos-aarch64-none/lib/python3.14/_pyrepl/unix_console.py", line 377, in restore
    signal.signal(signal.SIGWINCH, self.old_sigwinch)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hyi/.local/share/uv/python/cpython-3.14.0rc2-macos-aarch64-none/lib/python3.14/signal.py", line 58, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread of the main interpreter
>>> 
Image

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesOS-linuxOS-macstdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions