From fd5c130731075fef0895e35017bd0457137a9f74 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 21 Jun 2015 08:49:19 +0530 Subject: [PATCH] Ensure max number of open file handles is 1024 on windows as well It is 512 by default. --- src/calibre/startup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calibre/startup.py b/src/calibre/startup.py index 0297a469db..8796571c43 100644 --- a/src/calibre/startup.py +++ b/src/calibre/startup.py @@ -62,7 +62,14 @@ if not _run_once: # # Ensure that the max number of open files is at least 1024 - if not iswindows: + 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)) + else: import resource soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE) if soft < 1024: