[New-bugs-announce] [issue33635] OSError when using pathlib.Path.rglob() to list device files

Victor Domingos report at bugs.python.org
Thu May 24 08:15:27 EDT 2018


New submission from Victor Domingos <editor.arcosonline at gmail.com>:

This method fails with an error when it finds a character or block device (like those found in /dev on macOS). However, in the same machine, with the same Python version, the alternative os.walk() performs basically the same job with no errors. I am not sure if that error is the expected behaviour, but I wasn't able to find a clear explanation in the docs. Anyway, it seems to me, as a user, that the os.walk() error-less behaviour is more desirable.

```
$ python3
Python 3.7.0b4 (v3.7.0b4:eb96c37699, May  2 2018, 04:13:13) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> from pathlib import Path
>>> [f for f in Path(os.path.expanduser('/dev')).rglob("*") if f.is_file()]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <listcomp>
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py", line 1344, in is_file
    return S_ISREG(self.stat().st_mode)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py", line 1140, in stat
    return self._accessor.stat(self)
OSError: [Errno 9] Bad file descriptor: '/dev/fd/3'
>>> 
```

----------
components: Library (Lib)
messages: 317566
nosy: Victor Domingos
priority: normal
severity: normal
status: open
title: OSError when using pathlib.Path.rglob() to list device files
type: crash
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33635>
_______________________________________


More information about the New-bugs-announce mailing list