mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Use pipe worker for the main render process
This commit is contained in:
parent
8972d63efd
commit
facc4045d4
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user