diff --git a/src/calibre/utils/ipc/launch.py b/src/calibre/utils/ipc/launch.py index 9c50208935..e13c9e0cb6 100644 --- a/src/calibre/utils/ipc/launch.py +++ b/src/calibre/utils/ipc/launch.py @@ -183,6 +183,12 @@ class Worker(object): args['stdout'] = _windows_null_file args['stderr'] = subprocess.STDOUT + if not iswindows: + # Close inherited file descriptors in worker + # On windows, this is done in the worker process + # itself + args['close_fds'] = True + self.child = subprocess.Popen(cmd, **args) if 'stdin' in args: self.child.stdin.close() diff --git a/src/calibre/utils/ipc/worker.py b/src/calibre/utils/ipc/worker.py index 42618f7996..4d23d5a928 100644 --- a/src/calibre/utils/ipc/worker.py +++ b/src/calibre/utils/ipc/worker.py @@ -47,6 +47,11 @@ PARALLEL_FUNCS = { ('calibre.ebooks.metadata.worker', 'save_book', 'notification'), } +try: + MAXFD = os.sysconf("SC_OPEN_MAX") +except: + MAXFD = 256 + class Progress(Thread): def __init__(self, conn): @@ -80,7 +85,7 @@ def main(): # Close open file descriptors inherited from parent # as windows locks open files if iswindows: - os.closerange(3, 1000) + os.closerange(3, MAXFD) from calibre.constants import isosx if isosx and 'CALIBRE_WORKER_ADDRESS' not in os.environ: # On some OS X computers launchd apparently tries to