Skip to content

sys.addaudithook(None) breaks the REPL #125852

@devdanzin

Description

@devdanzin

Bug report

Bug description:

Running the code below exits the interpreter if using PyREPL, results in an infinite loop in basic REPL and breaks IDLE. Nevertheless, it might be a case of "just don't do that then".

import sys
sys.addaudithook(None)

It might be necessary to hit Enter again to see this behavior.

In basic REPL, the loop prints (and doesn't seem to be interruptible with Ctrl+C):

Exception ignored in audit hook:
TypeError: 'NoneType' object is not callable

In Windows with PyREPL, the error is (and then the interpreter exits):

>>> Exception ignored in audit hook:
TypeError: 'NoneType' object is not callable
Exception ignored in audit hook:
TypeError: 'NoneType' object is not callable
Traceback (most recent call last):
  File "~\PycharmProjects\cpython\Lib\runpy.py", line 198, in _run_module_as_main
  File "~\PycharmProjects\cpython\Lib\runpy.py", line 88, in _run_code
  File "~\PycharmProjects\cpython\Lib\_pyrepl\__main__.py", line 6, in <module>
  File "~\PycharmProjects\cpython\Lib\_pyrepl\main.py", line 59, in interactive_console
  File "~\PycharmProjects\cpython\Lib\_pyrepl\simple_interact.py", line 151, in run_multiline_interactive_console
  File "~\PycharmProjects\cpython\Lib\_pyrepl\readline.py", line 389, in multiline_input
  File "~\PycharmProjects\cpython\Lib\_pyrepl\reader.py", line 801, in readline
  File "~\PycharmProjects\cpython\Lib\_pyrepl\reader.py", line 756, in handle1
  File "~\PycharmProjects\cpython\Lib\_pyrepl\windows_console.py", line 486, in wait
TypeError: 'NoneType' object is not callable

In Linux with PyREPL the error is (and then the interpreter exits):

Exception ignored in audit hook:
TypeError: 'NoneType' object is not callable
Traceback (most recent call last):
  File "~/projects/mycpython/Lib/_pyrepl/unix_console.py", line 451, in getheightwidth
  File "<frozen os>", line 708, in __getitem__
KeyError: 'LINES'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "~/projects/mycpython/Lib/_pyrepl/__main__.py", line 6, in <module>
  File "~/projects/mycpython/Lib/_pyrepl/main.py", line 59, in interactive_console
  File "~/projects/mycpython/Lib/_pyrepl/simple_interact.py", line 151, in run_multiline_interactive_console
  File "~/projects/mycpython/Lib/_pyrepl/readline.py", line 389, in multiline_input
  File "~/projects/mycpython/Lib/_pyrepl/reader.py", line 795, in readline
  File "~/projects/mycpython/Lib/_pyrepl/historical_reader.py", line 302, in prepare
  File "~/projects/mycpython/Lib/_pyrepl/reader.py", line 635, in prepare
  File "~/projects/mycpython/Lib/_pyrepl/unix_console.py", line 349, in prepare
  File "~/projects/mycpython/Lib/_pyrepl/unix_console.py", line 454, in getheightwidth
TypeError: 'NoneType' object is not callable
Exception ignored in audit hook:
TypeError: 'NoneType' object is not callable

It also breaks IDLE:

----------------------------------------
Unhandled exception in user code execution server!'
Thread: SockThread
IDLE Client Address: ('127.0.0.1', 59153)
Request: <socket.socket fd=340, family=2, type=1, proto=0, laddr=('127.0.0.1', 59154), raddr=('127.0.0.1', 59153)>

Exception in thread SockThread:
Traceback (most recent call last):
  File "~\scoop\apps\python\current\Lib\socketserver.py", line 318, in _handle_request_noblock
  File "~\scoop\apps\python\current\Lib\socketserver.py", line 349, in process_request
  File "~\scoop\apps\python\current\Lib\socketserver.py", line 362, in finish_request
  File "~\scoop\apps\python\current\Lib\idlelib\rpc.py", line 514, in __init__
  File "~\scoop\apps\python\current\Lib\socketserver.py", line 761, in __init__
  File "~\scoop\apps\python\current\Lib\idlelib\run.py", line 547, in handle
  File "~\scoop\apps\python\current\Lib\idlelib\rpc.py", line 291, in getresponse
  File "~\scoop\apps\python\current\Lib\idlelib\rpc.py", line 311, in _getresponse
  File "~\scoop\apps\python\current\Lib\idlelib\rpc.py", line 432, in pollresponse
  File "~\scoop\apps\python\current\Lib\idlelib\rpc.py", line 388, in pollmessage
TypeError: 'NoneType' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~\scoop\apps\python\current\Lib\threading.py", line 1075, in _bootstrap_inner
  File "~\scoop\apps\python\current\Lib\threading.py", line 1012, in run
  File "~\scoop\apps\python\current\Lib\idlelib\run.py", line 205, in manage_socket
  File "~\scoop\apps\python\current\Lib\socketserver.py", line 298, in handle_request
  File "~\scoop\apps\python\current\Lib\socketserver.py", line 320, in _handle_request_noblock
  File "~\scoop\apps\python\current\Lib\idlelib\run.py", line 421, in handle_error
  File "~\scoop\apps\python\current\Lib\traceback.py", line 180, in print_exc
  File "~\scoop\apps\python\current\Lib\traceback.py", line 124, in print_exception
  File "~\scoop\apps\python\current\Lib\traceback.py", line 728, in __init__
TypeError: 'NoneType' object is not callable

CPython versions tested on:

3.10, 3.12, 3.13, 3.14, CPython main branch

Operating systems tested on:

Linux, Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions