diff --git a/src/calibre/gui2/viewer/convert_book.py b/src/calibre/gui2/viewer/convert_book.py index 109336c440..c212b9669f 100644 --- a/src/calibre/gui2/viewer/convert_book.py +++ b/src/calibre/gui2/viewer/convert_book.py @@ -14,9 +14,11 @@ from hashlib import sha1 from calibre import walk from calibre.constants import cache_dir, iswindows +from calibre.ptempfile import TemporaryFile from calibre.srv.render_book import RENDER_VERSION -from calibre.utils.ipc.simple_worker import fork_job +from calibre.utils.ipc.simple_worker import start_pipe_worker from calibre.utils.lock import ExclusiveFile +from calibre.utils.serialize import msgpack_dumps from calibre.utils.short_uuid import uuid4 from polyglot.builtins import as_bytes, as_unicode, iteritems @@ -120,10 +122,16 @@ def prepare_convert(temp_path, key, st): def do_convert(path, temp_path, key, instance): tdir = os.path.join(temp_path, instance['path']) - fork_job('calibre.srv.render_book', 'render_for_viewer', args=( - path, tdir, {'size': instance['file_size'], 'mtime': instance['file_mtime'], 'hash': key}, - ), timeout=3000, no_output=True - ) + with TemporaryFile('log.txt') as logpath, open(logpath, 'w+b') as logf: + p = start_pipe_worker('from calibre.srv.render_book import viewer_main; viewer_main()', stdout=logf, stderr=logf) + p.stdin.write(msgpack_dumps(( + path, tdir, {'size': instance['file_size'], 'mtime': instance['file_mtime'], 'hash': key}, + ))) + p.stdin.close() + if p.wait() != 0: + with lopen(logpath, 'rb') as logf: + raise Exception('Failed to convert book: {} with errors:\n{}'.format( + path, logf.read().decode('utf-8', 'replace'))) size = 0 for f in walk(tdir): size += os.path.getsize(f) diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index 17e0584a19..6f9eb9e514 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -861,5 +861,11 @@ def render_for_viewer(path, out_dir, book_hash): ) +def viewer_main(): + stdin = getattr(sys.stdin, 'buffer', sys.stdin) + args = msgpack_loads(stdin.read()) + render_for_viewer(*args) + + if __name__ == '__main__': render_for_viewer(sys.argv[-2], sys.argv[-1], None)