Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,13 @@ features:

Return a string representing the current working directory.

.. function:: getdtablesize()

Return the maximum number of files a process can have open.

.. warning::

This function currently only supports unix-like system.

.. function:: getcwdb()

Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ def test_getcwd(self):
cwd = os.getcwd()
self.assertIsInstance(cwd, str)

def test_getdtablesize(self):
curr_system = platform.system()
if curr_system == 'Windows':
try:
size = os.getdtablesize()
except NotImplementedError as e:
self.assertIsInstance(e, NotImplementedError)
else:
self.fail('No NotImplementedError is thrown')
else:
size = os.getdtablesize()
self.assertIsInstance(size, int)

def test_getcwd_long_path(self):
# bpo-37412: On Linux, PATH_MAX is usually around 4096 bytes. On
# Windows, MAX_PATH is defined as 260 characters, but Windows supports
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added :func:`os.getdtablesize` to :mod:`os` (supported only on unix-like
systems)
18 changes: 18 additions & 0 deletions Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4219,6 +4219,34 @@
}


/*[clinic input]
os.getdtablesize
Return the maximum number of files a process can have open.
[clinic start generated code]*/

static PyObject *
os_getdtablesize_impl(PyObject *module)
{
PyObject *max_fptable_size;
int size;

#ifdef MS_WINDOWS
PyErr_SetString(PyExc_NotImplementedError,
"this function is not supported on windows");
if (PyErr_Occurred()) {
return NULL;
}
#else /* !Unix-like */
size = getdtablesize();
#endif /* !MS_WINDOWS */
max_fptable_size = PyLong_FromLong(size);
if (max_fptable_size == NULL)
return NULL;

return max_fptable_size;
}

Check warning on line 4249 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

uninitialized local variable 'size' used [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 4249 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

uninitialized local variable 'size' used [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 4249 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

uninitialized local variable 'size' used [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 4249 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

uninitialized local variable 'size' used [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 4249 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

uninitialized local variable 'size' used [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 4249 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

uninitialized local variable 'size' used [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 4249 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

uninitialized local variable 'size' used [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 4249 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

uninitialized local variable 'size' used [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
#if ((!defined(HAVE_LINK)) && defined(MS_WINDOWS))
#define HAVE_LINK 1
#endif
Expand Down Expand Up @@ -16843,6 +16871,7 @@
OS_CTERMID_METHODDEF
OS_GETCWD_METHODDEF
OS_GETCWDB_METHODDEF
OS_GETDTABLESIZE_METHODDEF
OS_LINK_METHODDEF
OS_LISTDIR_METHODDEF
OS_LISTDRIVES_METHODDEF
Expand Down
Loading