mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Fix writing to stdout/stderr in pool worker processes on windows not working
This commit is contained in:
parent
ad6405c573
commit
a7899be02d
@ -16,7 +16,7 @@ from calibre.ptempfile import PersistentTemporaryFile, base_dir
|
||||
if iswindows:
|
||||
import win32process
|
||||
try:
|
||||
_windows_null_file = open(os.devnull, 'wb')
|
||||
windows_null_file = open(os.devnull, 'wb')
|
||||
except:
|
||||
raise RuntimeError('NUL file missing in windows. This indicates a'
|
||||
' corrupted windows. You should contact Microsoft'
|
||||
@ -212,7 +212,7 @@ class Worker(object):
|
||||
# On windows when using the pythonw interpreter,
|
||||
# stdout, stderr and stdin may not be valid
|
||||
args['stdin'] = subprocess.PIPE
|
||||
args['stdout'] = _windows_null_file
|
||||
args['stdout'] = windows_null_file
|
||||
args['stderr'] = subprocess.STDOUT
|
||||
|
||||
if not iswindows:
|
||||
|
@ -12,6 +12,7 @@ from collections import namedtuple
|
||||
from Queue import Queue
|
||||
|
||||
from calibre import detect_ncpus, as_unicode, prints
|
||||
from calibre.constants import iswindows
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.utils import join_with_timeout
|
||||
from calibre.utils.ipc import eintr_retry_call
|
||||
@ -24,6 +25,11 @@ File = namedtuple('File', 'name')
|
||||
|
||||
MAX_SIZE = 30 * 1024 * 1024 # max size of data to send over the connection (old versions of windows cannot handle arbitrary data lengths)
|
||||
|
||||
worker_kwargs = {'stdout':None}
|
||||
if iswindows and getattr(sys, 'gui_app', False):
|
||||
from calibre.utils.ipc.launch import windows_null_file
|
||||
worker_kwargs['stdout'] = worker_kwargs['stderr'] = windows_null_file
|
||||
|
||||
class Failure(Exception):
|
||||
|
||||
def __init__(self, tf):
|
||||
@ -132,7 +138,7 @@ class Pool(Thread):
|
||||
def create_worker(self):
|
||||
from calibre.utils.ipc.simple_worker import start_pipe_worker
|
||||
p = start_pipe_worker(
|
||||
'from {0} import run_main, {1}; run_main({1})'.format(self.__class__.__module__, 'worker_main'), stdout=None)
|
||||
'from {0} import run_main, {1}; run_main({1})'.format(self.__class__.__module__, 'worker_main'), **worker_kwargs)
|
||||
sys.stdout.flush()
|
||||
eintr_retry_call(p.stdin.write, self.worker_data)
|
||||
p.stdin.flush(), p.stdin.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user