mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
e9c8ffe5e9
commit
58ae632731
@ -64,11 +64,8 @@ if not _run_once:
|
|||||||
# Ensure that the max number of open files is at least 1024
|
# Ensure that the max number of open files is at least 1024
|
||||||
if iswindows:
|
if iswindows:
|
||||||
# See https://msdn.microsoft.com/en-us/library/6e3b887c.aspx
|
# See https://msdn.microsoft.com/en-us/library/6e3b887c.aspx
|
||||||
import ctypes
|
if hasattr(winutil, 'setmaxstdio'):
|
||||||
msvcrt = ctypes.cdll.msvcrt
|
winutil.setmaxstdio(max(1024, winutil.getmaxstdio()))
|
||||||
soft, hard = msvcrt._getmaxstdio(), 2048
|
|
||||||
if soft < 1024:
|
|
||||||
msvcrt._setmaxstdio(min(1024, hard))
|
|
||||||
else:
|
else:
|
||||||
import resource
|
import resource
|
||||||
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
|
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
|
||||||
|
@ -215,6 +215,19 @@ winutil_prepare_for_restart(PyObject *self, PyObject *args) {
|
|||||||
Py_RETURN_NONE;
|
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 *
|
static PyObject *
|
||||||
winutil_strftime(PyObject *self, PyObject *args)
|
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"
|
"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}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user