Skip to content

High CPU usage in Buku interactive mode on Windows due to pyreadline3 polling #896

Description

@jackanory101
# buku --debug
[DEBUG] buku v5.1
[DEBUG] Python v3.13.12

Windows 10

When dropped into interactive mode python.exe immediately starts consuming CPU cycles between 7~11% even when not actively using buku in prompt mode. When I exit buku, python.exe exits.

$ py313.sh pip show buku
Name: buku
Version: 5.1
Summary: Bookmark manager like a text-based mini-web.
Home-page: https://github.com/jarun/buku
Author:
Author-email: Arun Prakash Jana <engineerarun@gmail.com>
License-Expression: GPL-3.0-or-later
Location: C:\Users\tom\Documents\bin\apps\python\python-313\Lib\site-packages
Requires: beautifulsoup4, certifi, colorama, cryptography, html5lib, pyreadline3, urllib3
Required-by:
C:\WINDOWS\system32>py-spy.exe top --pid 16628

Collecting samples from '"....python.exe"  "....Scripts\buku.exe" -t biz: + geo:eire - dev:localhost' (python v3.13.12)
Total Samples 1100
GIL: 12.00%, Active: 62.00%, Threads: 1

  %Own   %Total  OwnTime  TotalTime  Function (filename)
 62.00%  62.00%    6.89s     6.89s   get (pyreadline3\console\console.py) <----- HERE HERE HERE
  0.00%  62.00%   0.000s     6.89s   _readline_from_keyboard (pyreadline3\rlmain.py)
  0.00%  62.00%   0.000s     6.89s   hook_wrapper_23 (pyreadline3\console\console.py)
  0.00%  62.00%   0.000s     6.89s   prompt (buku.py)
  0.00%  62.00%   0.000s     6.89s   <module> (__main__.py)
  0.00%  62.00%   0.000s     6.89s   readline (pyreadline3\rlmain.py)
  0.00%  62.00%   0.000s     6.89s   _run_code (<frozen runpy>)
  0.00%  62.00%   0.000s     6.89s   read_in (buku.py)
  0.00%  62.00%   0.000s     6.89s   main (buku.py)
  0.00%  62.00%   0.000s     6.89s   getkeypress (pyreadline3\console\console.py)
  0.00%  62.00%   0.000s     6.89s   _run_module_as_main (<frozen runpy>)
  0.00%  62.00%   0.000s     6.89s   _readline_from_keyboard_poll (pyreadline3\rlmain.py)

Summarized by ChatGPT

Bug report: High CPU usage in Buku interactive mode on Windows due to pyreadline3 polling

Environment:

  • Windows (CMD)
  • Python 3.13.12 (MSVC build)
  • Buku installed via pip
  • Dependency: pyreadline3 3.5.6 (installed as dependency of Buku)

Problem:
When running buku in interactive mode (prompt UI), the process continuously consumes ~7–11% CPU while idle at the prompt.

This occurs even when no user input is being entered.

Expected behaviour:
Interactive prompt should remain idle and consume near 0% CPU while waiting for input.

Actual behaviour:
Sustained CPU usage (~7–11%) while idle at the Buku prompt.

Investigation results:

  • CPU usage disappears when running Python with -S (disabling site), but this is not directly related to Buku itself.
  • Profiling (py-spy) shows the hotspot is inside:
pyreadline3\console\console.py → get()  
pyreadline3\rlmain.py → _readline_from_keyboard_poll()  
  • ~62% of sampled time is spent in pyreadline3 console input polling functions.

  • Stack traces show repeated calls to Windows console APIs such as:

    • GetNumberOfConsoleInputEvents
    • GetConsoleScreenBufferInfoEx
    • WriteConsoleW

Root cause:
pyreadline3 is using a polling-based console input loop on Windows in Buku’s interactive prompt, resulting in a busy-wait loop and sustained CPU usage while idle.

Impact:

  • Constant CPU usage when Buku is open in interactive mode
  • Unnecessary power/battery consumption
  • Affects usability of interactive mode on Windows

Workaround:

  • Avoid interactive mode (buku -s / non-interactive usage)
  • Removing pyreadline3 stops CPU usage but breaks Buku’s interactive prompt due to missing readline dependency

Notes:
This appears to be a Windows-specific issue in pyreadline3’s input handling rather than Buku core logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions