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

Exiting Python REPL prompt with user without home directory throws error in atexit._run_exitfuncs #64090

Closed
vajrasky mannequin opened this issue Dec 5, 2013 · 14 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@vajrasky
Copy link
Mannequin

vajrasky mannequin commented Dec 5, 2013

BPO 19891
Nosy @pitrou, @bitdancer, @methane, @vajrasky, @asottile, @miss-islington
PRs
  • bpo-19891: ignore error writing history with no homedir #8483
  • [3.7] bpo-19891: Ignore error while writing history file (GH-8483) #8684
  • [3.6] bpo-19891: Ignore error while writing history file (GH-8483) #8685
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-08-06.09:42:26.458>
    created_at = <Date 2013-12-05.04:22:10.425>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'Exiting Python REPL prompt with user without home directory throws error in atexit._run_exitfuncs'
    updated_at = <Date 2018-08-06.09:42:26.454>
    user = 'https://github.com/vajrasky'

    bugs.python.org fields:

    activity = <Date 2018-08-06.09:42:26.454>
    actor = 'methane'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-08-06.09:42:26.458>
    closer = 'methane'
    components = ['Library (Lib)']
    creation = <Date 2013-12-05.04:22:10.425>
    creator = 'vajrasky'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 19891
    keywords = ['patch']
    message_count = 14.0
    messages = ['205273', '205295', '205298', '205300', '205304', '205371', '205372', '205373', '218490', '305161', '322435', '323184', '323186', '323187']
    nosy_count = 8.0
    nosy_names = ['pitrou', 'r.david.murray', 'methane', 'ejo', 'vajrasky', 'Anthony Sottile', 'dj3ei', 'miss-islington']
    pr_nums = ['8483', '8684', '8685']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue19891'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Dec 5, 2013

    $ sudo adduser --no-create-home cutecat
    Adding user `cutecat' ...
    Adding new group `cutecat' (1007) ...
    Adding new user `cutecat' (1005) with group `cutecat' ...
    Not creating home directory `/home/cutecat'.
    Enter new UNIX password: 
    Retype new UNIX password: 
    passwd: password updated successfully
    Changing the user information for cutecat
    Enter the new value, or press ENTER for the default
    	Full Name []: 
    	Room Number []: 
    	Work Phone []: 
    	Home Phone []: 
    	Other []: 
    Is the information correct? [Y/n] Y
    
    $ su cutecat
    Password: 
    $ ./python
    Python 3.4.0b1 (default:1f1498fe50e5, Dec  5 2013, 09:48:25) 
    [GCC 4.7.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    Error in atexit._run_exitfuncs:
    FileNotFoundError: [Errno 2] No such file or directory
    $

    Python 2.7 and 3.3 do not throw error.

    $ ./python
    Python 3.3.3+ (3.3:07425df887b5+, Dec  2 2013, 12:27:06) 
    [GCC 4.7.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    [60778 refs]
    [41580 refs]
    $
    
    $ ./python
    Python 2.7.6+ (2.7:181ced5bf0be, Dec  4 2013, 11:23:42) 
    [GCC 4.7.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    $

    @vajrasky vajrasky mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Dec 5, 2013
    @vajrasky vajrasky mannequin closed this as completed Dec 5, 2013
    @vajrasky vajrasky mannequin added the invalid label Dec 5, 2013
    @bitdancer
    Copy link
    Member

    This is presumably due to the new default enabling of readline, where it is trying to save the history file when it exits.

    @pitrou
    Copy link
    Member

    pitrou commented Dec 5, 2013

    For the record, why did you close as invalid?

    @bitdancer
    Copy link
    Member

    Not sure who you meant by 'you', but just in case you meant me, Vajrasky was the one who closed it.

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Dec 5, 2013

    I closed it because I could not reproduce it anymore.

    I think, it worked again after

    $ ./python -S

    I will open it again if I can consistently reproduce this bug.

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Dec 6, 2013

    Okay, this bug is valid. I can reproduce it in Ubuntu and Fedora.

    bash-4.2$ ./python
    Python 3.4.0b1 (default:7a668179d691, Dec  6 2013, 21:44:31) 
    [GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    Error in atexit._run_exitfuncs:
    FileNotFoundError: [Errno 2] No such file or directory
    bash-4.2$ ./python -S
    Python 3.4.0b1 (default:7a668179d691, Dec  6 2013, 21:44:31) 
    [GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux
    >>> 
    bash-4.2$

    @vajrasky vajrasky mannequin reopened this Dec 6, 2013
    @vajrasky vajrasky mannequin removed the invalid label Dec 6, 2013
    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Dec 6, 2013

    Additional information:

    When I created /home/cutecat with another user account.

    bash-4.2$ ./python
    Python 3.4.0b1 (default:7a668179d691, Dec  6 2013, 21:44:31) 
    [GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    Error in atexit._run_exitfuncs:
    PermissionError: [Errno 13] Permission denied

    Of course, so I change the ownership of /home/cutecat to cutecat. Then it works.

    bash-4.2$ ./python
    Python 3.4.0b1 (default:7a668179d691, Dec  6 2013, 21:44:31) 
    [GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    bash-4.2$

    So what did it try to do in /home/cutecat?

    [sky@localhost cpython]$ ls -la /home/cutecat/
    total 8
    drwxr-xr-x. 2 cutecat root 4096 Dec 6 21:50 .
    drwxr-xr-x. 4 root root 4096 Dec 6 21:50 ..
    -rw-------. 1 cutecat cutecat 0 Dec 6 21:50 .python_history

    So I leave to core Python developers to decide whether this ticket is valid or not.

    @pitrou
    Copy link
    Member

    pitrou commented Dec 6, 2013

    The main question here is whether "interactive user without a home directory" is a valid / common use case. I think silencing the FileNotFoundError would be ok.

    (however, the "home directory with wrong permissions" case sounds crazy)

    @ejo
    Copy link
    Mannequin

    ejo mannequin commented May 13, 2014

    I'm getting the same PermissionError 13:

    Error in atexit._run_exitfuncs:
    PermissionError: [Errno 13] Permission denied

    My case is: I'm running Python 3.4.0 as a non-root user in a docker.io container built on ubuntu 14.04. This user was created during the creation (Dockerfile) of the container. The user has a home directory and that directory appears to have the usual/proper permissions. When I exit the python3 REPL I get this error even if all I did was start python3 from the command line and then immediately exit.

    So maybe the cause is other, or more subtle, than just a user with no home dir or home dir with unusual perms?

    @dj3ei
    Copy link
    Mannequin

    dj3ei mannequin commented Oct 28, 2017

    I can easily reproduce the problem with Docker,
    and it does seem to be a permission problem:

        $ docker run -ti --rm --user="7777:7777" python:3.6.3-jessie bash -c "python3"
        Python 3.6.3 (default, Oct 10 2017, 02:29:16) 
        [GCC 4.9.2] on linux
        Type "help", "copyright", "credits" or "license" for more information.
        >>> 
        Error in atexit._run_exitfuncs:
        PermissionError: [Errno 13] Permission denied
    
        $ docker run -ti --rm --user="7777:7777" python:3.6.3-jessie bash -c "HOME=/tmp python3; ls -lta /tmp"
        Python 3.6.3 (default, Oct 10 2017, 02:29:16) 
        [GCC 4.9.2] on linux
        Type "help", "copyright", "credits" or "license" for more information.
        >>> 
        total 8
        drwxrwxrwt  2 root root 4096 Oct 28 14:10 .
        drwxr-xr-x 55 root root 4096 Oct 28 14:10 ..
        -rw-------  1 7777 7777    0 Oct 28 14:10 .python_history

    @asottile
    Copy link
    Mannequin

    asottile mannequin commented Jul 26, 2018

    I was able to reproduce both the PermissionError and the FileNotFoundError under these circumstances:

    $ docker run --user 123:123 -ti python python
    Python 3.7.0 (default, Jul 17 2018, 11:04:33) 
    [GCC 6.3.0 20170516] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    Error in atexit._run_exitfuncs:
    PermissionError: [Errno 13] Permission denied
    
    
    $ docker run --user nobody -ti python python
    Python 3.7.0 (default, Jul 17 2018, 11:04:33) 
    [GCC 6.3.0 20170516] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    Error in atexit._run_exitfuncs:
    FileNotFoundError: [Errno 2] No such file or directory

    In the former, the home directory is / (not writable). In the latter, the homedir is /nonexistent, which, well, doesn't exist.

    My patch addresses both of these errors.

    @methane
    Copy link
    Member

    methane commented Aug 6, 2018

    New changeset b249966 by INADA Naoki (Anthony Sottile) in branch 'master':
    bpo-19891: Ignore error while writing history file (GH-8483)
    b249966

    @miss-islington
    Copy link
    Contributor

    New changeset 416f343 by Miss Islington (bot) in branch '3.7':
    bpo-19891: Ignore error while writing history file (GH-8483)
    416f343

    @miss-islington
    Copy link
    Contributor

    New changeset e20d31c by Miss Islington (bot) in branch '3.6':
    bpo-19891: Ignore error while writing history file (GH-8483)
    e20d31c

    @methane methane added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir and removed extension-modules C modules in the Modules dir labels Aug 6, 2018
    @methane methane closed this as completed Aug 6, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants