Skip to content

PyREPL raises exception while trying to write to the history file on a read-only file system #128066

Closed
@vladimir-poghosyan

Description

@vladimir-poghosyan

Bug report

Bug description:

When using new Python 3.13 pyrepl on a read-only file system, attempting to exit the REPL raises the following exception: OSError: [Errno 30] Read-only file system: '/root/.python_history'. The same setup works with Python 3.12.

dev:/home/dev$ docker run -it --read-only python:3.12-slim-bookworm python3
Python 3.12.7 (main, Nov 12 2024, 02:26:49) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello')
hello
>>> exit()
dev:/home/dev$ docker run -it --read-only python:3.13-slim-bookworm python3
Python 3.13.1 (main, Dec  4 2024, 20:40:24) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello')
hello
>>> exit()
Exception ignored in atexit callback <function register_readline.<locals>.write_history at 0x7f56689a3600>:
Traceback (most recent call last):
  File "<frozen site>", line 574, in write_history
  File "/usr/local/lib/python3.13/_pyrepl/readline.py", line 453, in write_history_file
    f = open(os.path.expanduser(filename), "w",
OSError: [Errno 30] Read-only file system: '/root/.python_history'

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Linux

Linked PRs

Activity

ZeroIntensity

ZeroIntensity commented on Dec 18, 2024

@ZeroIntensity
Member

I think the easiest fix would be to catch OSErrors there, and just log a warning if something goes wrong.

skirpichev

skirpichev commented on Dec 20, 2024

@skirpichev
Contributor

It's silly that we get this error only at the end of session.

Rather than catch OSError, maybe we should map EROFS errno to PermissionError on Linux. (Call to write_history_file() is wrapped with except (FileNotFoundError, PermissionError).)

feoh

feoh commented on May 20, 2025

@feoh
Contributor

Fix in hand. Tested locally by stealing the official Python image build dockerfile but using my own modified tarball with the fix.

╭─cpatti at rocinante in ~/src/personal 25-05-20 - 14:18:58
╰─○ docker run -it --read-only pyrepl_tst python3                       <region:us-east-1>
zsh: correct 'python3' to 'python' [nyae]? n
Python 3.15.0a0 (heads/cpatti_issue_128066-dirty:01225ff4a74, May 20 2025, 18:17:11) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hellorld!")
Hellorld!
>>>
added a commit that references this issue on May 20, 2025

gh-128066: Properly handle history file writes for RO fs on PyREPL (g…

c91ad5d
added a commit that references this issue on May 20, 2025

pythongh-128066: Properly handle history file writes for RO fs on PyR…

added a commit that references this issue on May 20, 2025

[3.13] pythongh-128066: Properly handle history file writes for RO fs…

d6a3cdc

4 remaining items

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.13bugs and security fixes3.14bugs and security fixestopic-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

      PyREPL raises exception while trying to write to the history file on a read-only file system · Issue #128066 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant