Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vladimir-poghosyan opened this issue Dec 18, 2024 · 2 comments
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@vladimir-poghosyan
Copy link

vladimir-poghosyan commented Dec 18, 2024

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

@vladimir-poghosyan vladimir-poghosyan added the type-bug An unexpected behavior, bug, or error label Dec 18, 2024
@tomasr8 tomasr8 added the topic-repl Related to the interactive shell label Dec 18, 2024
@ZeroIntensity ZeroIntensity added 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Dec 18, 2024
@ZeroIntensity
Copy link
Member

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

@skirpichev
Copy link
Member

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).)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants