This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Exiting Python REPL prompt with user without home directory throws error in atexit._run_exitfuncs
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, dj3ei, ejo, methane, miss-islington, pitrou, r.david.murray, vajrasky
Priority: low Keywords: patch

Created on 2013-12-05 04:22 by vajrasky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 8483 merged Anthony Sottile, 2018-07-26 15:43
PR 8684 merged miss-islington, 2018-08-06 08:28
PR 8685 merged miss-islington, 2018-08-06 08:28
Messages (14)
msg205273 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-12-05 04:22
$ 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.
>>> 
$
msg205295 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-12-05 13:36
This is presumably due to the new default enabling of readline, where it is trying to save the history file when it exits.
msg205298 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-12-05 13:55
For the record, why did you close as invalid?
msg205300 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-12-05 13:58
Not sure who you meant by 'you', but just in case you meant me, Vajrasky was the one who closed it.
msg205304 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-12-05 15:04
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.
msg205371 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-12-06 13:49
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$
msg205372 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-12-06 13:54
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.
msg205373 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-12-06 13:56
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)
msg218490 - (view) Author: Eric Ongerth (ejo) Date: 2014-05-13 23:06
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?
msg305161 - (view) Author: Andreas Krüger (dj3ei) Date: 2017-10-28 14:13
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
msg322435 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2018-07-26 15:56
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.
msg323184 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2018-08-06 08:28
New changeset b2499669ef2e6dc9a2cdb49b4dc498e078167e26 by INADA Naoki (Anthony Sottile) in branch 'master':
bpo-19891: Ignore error while writing history file (GH-8483)
https://github.com/python/cpython/commit/b2499669ef2e6dc9a2cdb49b4dc498e078167e26
msg323186 - (view) Author: miss-islington (miss-islington) Date: 2018-08-06 09:03
New changeset 416f3435c536c5197f5c6a23504955cf717df200 by Miss Islington (bot) in branch '3.7':
bpo-19891: Ignore error while writing history file (GH-8483)
https://github.com/python/cpython/commit/416f3435c536c5197f5c6a23504955cf717df200
msg323187 - (view) Author: miss-islington (miss-islington) Date: 2018-08-06 09:15
New changeset e20d31cdb33bdfee68bce059f9a9c7ce71b035fe by Miss Islington (bot) in branch '3.6':
bpo-19891: Ignore error while writing history file (GH-8483)
https://github.com/python/cpython/commit/e20d31cdb33bdfee68bce059f9a9c7ce71b035fe
History
Date User Action Args
2022-04-11 14:57:55adminsetgithub: 64090
2018-08-06 09:42:26methanesetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
components: + Library (Lib), - Extension Modules
versions: + Python 3.7, Python 3.8, - Python 3.3, Python 3.4
2018-08-06 09:15:51miss-islingtonsetmessages: + msg323187
2018-08-06 09:03:52miss-islingtonsetnosy: + miss-islington
messages: + msg323186
2018-08-06 08:28:51miss-islingtonsetpull_requests: + pull_request8180
2018-08-06 08:28:41miss-islingtonsetpull_requests: + pull_request8179
2018-08-06 08:28:30methanesetnosy: + methane
messages: + msg323184
2018-07-26 15:56:36Anthony Sottilesetnosy: + Anthony Sottile
messages: + msg322435
2018-07-26 15:43:00Anthony Sottilesetkeywords: + patch
stage: patch review
pull_requests: + pull_request8005
2017-10-28 14:13:09dj3eisetnosy: + dj3ei

messages: + msg305161
versions: + Python 3.6
2014-05-13 23:06:07ejosetnosy: + ejo
messages: + msg218490
2013-12-06 13:56:12pitrousetpriority: normal -> low

messages: + msg205373
versions: + Python 3.3
2013-12-06 13:54:16vajraskysetmessages: + msg205372
2013-12-06 13:49:16vajraskysetstatus: closed -> open
resolution: not a bug -> (no value)
messages: + msg205371
2013-12-05 15:04:33vajraskysetmessages: + msg205304
2013-12-05 13:58:56r.david.murraysetmessages: + msg205300
2013-12-05 13:55:16pitrousetmessages: + msg205298
2013-12-05 13:36:05r.david.murraysetnosy: + r.david.murray, pitrou
messages: + msg205295
2013-12-05 08:37:24vajraskysetstatus: open -> closed
resolution: not a bug
2013-12-05 04:22:10vajraskycreate