Skip to content

glob empty return when ulimit -n is reached #103501

Open
@Uinelj

Description

@Uinelj

Bug report

When having a lot of opened files, glob can return an empty list rather than either raising an error or returning a non-empty list.

With a ulimit set at 256 (ulimit -n 256), and with a file named foo:

from glob import glob

print(glob("*")) # expectedly prints files in current folder
handles = [(x for x in open("foo")) for _ in range(253)] # create 253 file handles on foo
print(len(handles)) # returns 253
print(glob("*")) # prints []

My intuition is that glob should inform the user that it couldn't do its job properly (like open raises OSError if we try to open too many files), because right now there's an uncertainty on whether a given folder is empty or ulimit -n has been reached.

An OSError is caught in glob.py, but not propagated: https://github.com/python/cpython/blob/3.11/Lib/glob.py#L172

Your environment

  • CPython versions tested on: 3.10, 3.11
  • Operating system and architecture: macOS 12.0.1 (for 3.10), Debian 11 (for 3.11, from docker's python:latest), both x86_64

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions