Skip to content

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

Closed

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

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    topic-replRelated to the interactive shell
    on Sep 28, 2025
  2. yihong0618 commented on Sep 29, 2025

    @yihong0618
    ContributorAuthor

    update

    linux can also have this problem

    ./python -m asyncio
    >>> 
    Traceback (most recent call last):
      File "/home/hyi/cpython/Lib/_pyrepl/readline.py", line 395, in multiline_input
        return reader.readline()
               ~~~~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/reader.py", line 752, in readline
        self.restore()
        ~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/reader.py", line 608, in restore
        self.console.restore()
        ~~~~~~~~~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/unix_console.py", line 393, in restore
        signal.signal(signal.SIGWINCH, self.old_sigwinch)
        ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/hyi/cpython/Lib/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 "/home/hyi/cpython/Lib/_pyrepl/readline.py", line 395, in multiline_input
        return reader.readline()
               ~~~~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/reader.py", line 752, in readline
        self.restore()
        ~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/reader.py", line 608, in restore
        self.console.restore()
        ~~~~~~~~~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/unix_console.py", line 393, in restore
        signal.signal(signal.SIGWINCH, self.old_sigwinch)
        ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/hyi/cpython/Lib/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 "/home/hyi/cpython/Lib/_pyrepl/readline.py", line 395, in multiline_input
        return reader.readline()
               ~~~~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/reader.py", line 752, in readline
        self.restore()
        ~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/reader.py", line 608, in restore
        self.console.restore()
        ~~~~~~~~~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/unix_console.py", line 393, in restore
        signal.signal(signal.SIGWINCH, self.old_sigwinch)
        ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/hyi/cpython/Lib/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 "/home/hyi/cpython/Lib/_pyrepl/reader.py", line 748, in readline
        self.handle1()
        ~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/reader.py", line 731, in handle1
        self.do_cmd(cmd)
        ~~~~~~~~~~~^^^^^
      File "/home/hyi/cpython/Lib/_pyrepl/reader.py", line 656, in do_cmd
        command.do()
        ~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/commands.py", line 430, in do
        raise EOFError
    EOFError
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/hyi/cpython/Lib/_pyrepl/readline.py", line 395, in multiline_input
        return reader.readline()
               ~~~~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/reader.py", line 752, in readline
        self.restore()
        ~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/reader.py", line 608, in restore
        self.console.restore()
        ~~~~~~~~~~~~~~~~~~~~^^
      File "/home/hyi/cpython/Lib/_pyrepl/unix_console.py", line 393, in restore
        signal.signal(signal.SIGWINCH, self.old_sigwinch)
        ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/hyi/cpython/Lib/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
    >>> Terminated
    [hyi@rocky cpython]$ ^C
    [hyi@rocky cpython]$ uname -a
    Linux rocky 6.15.11-orbstack-00539-g9885ebd8e3f4 #1 SMP PREEMPT Fri Aug 22 08:24:56 UTC 2025 aarch64 aarch64 aarch64 GNU/Linux
    
    
  3. changed the title [-]python -m asyncio then Ctrl + z then fg will break the repl and raise error forever[/-] [+]Resuming `python -m asyncio` process is not properly handled[/+] on Sep 29, 2025
  4. changed the title [-]Resuming `python -m asyncio` process is not properly handled[/-] [+]Resuming `python -m asyncio` process is not properly handled on Unix-like platforms[/+] on Sep 29, 2025
  5. added
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Sep 29, 2025
  6. added a commit that references this issue on Oct 9, 2025
  7. added a commit that references this issue on Oct 9, 2025
  8. added a commit that references this issue on Oct 9, 2025
  9. added 2 commits that reference this issue on Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixes3.14bugs and security fixes3.15bugs 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