Python help() freezes the shell

Problem description:
Python’s help() global function, when run, freezes the shell completely.

Steps to reproduce:

  1. Create a Python Repl.
  2. Run python in the shell.
  3. Run help(help).
  4. For variables with longer “help” content (e.g. int), press Enter continuously for a quick while.
  5. Try pressing Ctrl + C to raise a KeyboardInterrupt and fail miserably.

Expected behavior:
Step 5 should have stopped IDLE from continue running, and the last Enter should have switched the help interactive interface to the normal IDLE.

Actual behavior:
No amount of keypressing/clicking help. Not even the clear button.
Reloading the tab, however, fixes the problem. Ctrl + Z also works; a possible explanation for that is found in this 2015 StackOverflow comment.

Press q to exit the help prompt.

Thanks. Just discovered that too. Still, this seems to be a bug.

No, this is probably not a bug. The help() function invokes pydoc, which generates the documentation you see. Pydoc itself may use less, which is for file navigation (so you can search and stuff).
For commands and stuff, see:
https://man7.org/linux/man-pages/man1/less.1.html

Pydoc:

SO:

How is me not being able to exit it with Ctrl + C not a bug? Mind you, the help interface is supposed to kill itself once it has displayed all it needs to.

The help() commands open up a linux program called less, for file navigation. This program is not related to python and happens to ignore keyboard interrupts (it doesn’t have any CTRL commands).
When it reaches the end of the file, it does not exit (it does say “END” to indicate the end of the file). Why? It’s supposed to be a file navigation program. You wouldn’t want to automatically exit the file when you’re trying to search stuff or read stuff. You just exit when you want to, with q.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.