Dont use ctypes for setmaxstdio() on windows

Once we move to the Universal CRT ctypes will not be able to load libc
at all.
This commit is contained in:
Kovid Goyal 2016-06-16 21:30:49 +05:30
parent e9c8ffe5e9
commit 58ae632731
2 changed files with 23 additions and 5 deletions

View File

@ -64,11 +64,8 @@ if not _run_once:
# Ensure that the max number of open files is at least 1024
if iswindows:
# See https://msdn.microsoft.com/en-us/library/6e3b887c.aspx
import ctypes
msvcrt = ctypes.cdll.msvcrt
soft, hard = msvcrt._getmaxstdio(), 2048
if soft < 1024:
msvcrt._setmaxstdio(min(1024, hard))
if hasattr(winutil, 'setmaxstdio'):
winutil.setmaxstdio(max(1024, winutil.getmaxstdio()))
else:
import resource
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)

View File

@ -215,6 +215,19 @@ winutil_prepare_for_restart(PyObject *self, PyObject *args) {
Py_RETURN_NONE;
}
static PyObject *
winutil_get_max_stdio(PyObject *self, PyObject *args) {
return Py_BuildValue("i", _getmaxstdio());
}
static PyObject *
winutil_set_max_stdio(PyObject *self, PyObject *args) {
int num = 0;
if (!PyArg_ParseTuple(args, "i", &num)) return NULL;
if (_setmaxstdio(num) == -1) return PyErr_SetFromErrno(PyExc_ValueError);
Py_RETURN_NONE;
}
static PyObject *
winutil_strftime(PyObject *self, PyObject *args)
{
@ -360,6 +373,14 @@ be a unicode string. Returns unicode strings."
"prepare_for_restart()\n\nRedirect output streams so that the child process does not lock the temp files"
},
{"getmaxstdio", winutil_get_max_stdio, METH_VARARGS,
"getmaxstdio()\n\nThe maximum number of open file handles."
},
{"setmaxstdio", winutil_set_max_stdio, METH_VARARGS,
"setmaxstdio(num)\n\nSet the maximum number of open file handles."
},
{NULL, NULL, 0, NULL}
};