Skip to content
Closed
Show file tree
Hide file tree
Changes from 13 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.

.. versionadded:: 3.14

.. availability:: Unix.

.. function:: getcwdb()

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

@unittest.skipUnless(hasattr(os, 'getdtablesize'), 'need os.getdtablesize()')
def test_getdtablesize(self):
size = os.getdtablesize()
self.assertIsInstance(size, int)
self.assertGreaterEqual(size, 0)

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.

17 changes: 17 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4218,6 +4218,22 @@ os_getcwdb_impl(PyObject *module)
return posix_getcwd(1);
}

#ifndef MS_WINDOWS
/*[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)
{
int size;

size = getdtablesize();
return PyLong_FromLong(size);
}
#endif /* !MS_WINDOWS */

#if ((!defined(HAVE_LINK)) && defined(MS_WINDOWS))
#define HAVE_LINK 1
Expand Down Expand Up @@ -16843,6 +16859,7 @@ static PyMethodDef posix_methods[] = {
OS_CTERMID_METHODDEF
OS_GETCWD_METHODDEF
OS_GETCWDB_METHODDEF
OS_GETDTABLESIZE_METHODDEF
OS_LINK_METHODDEF
OS_LISTDIR_METHODDEF
OS_LISTDRIVES_METHODDEF
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5149,7 +5149,7 @@ AC_CHECK_FUNCS([ \
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
gai_strerror getegid geteuid getgid getgrent getgrgid getgrgid_r \
getgrnam_r getgrouplist gethostname getitimer getloadavg getlogin \
getpeername getpgid getpid getppid getpriority _getpty \
getpeername getpgid getpid getppid getpriority _getpty getdtablesize \
getpwent getpwnam_r getpwuid getpwuid_r getresgid getresuid getrusage getsid getspent \
getspnam getuid getwd grantpt if_nameindex initgroups kill killpg lchown linkat \
lockf lstat lutimes madvise mbrtowc memrchr mkdirat mkfifo mkfifoat \
Expand Down
Loading