mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -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 import walk
|
||||||
from calibre.constants import cache_dir, iswindows
|
from calibre.constants import cache_dir, iswindows
|
||||||
|
from calibre.ptempfile import TemporaryFile
|
||||||
from calibre.srv.render_book import RENDER_VERSION
|
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.lock import ExclusiveFile
|
||||||
|
from calibre.utils.serialize import msgpack_dumps
|
||||||
from calibre.utils.short_uuid import uuid4
|
from calibre.utils.short_uuid import uuid4
|
||||||
from polyglot.builtins import as_bytes, as_unicode, iteritems
|
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):
|
def do_convert(path, temp_path, key, instance):
|
||||||
tdir = os.path.join(temp_path, instance['path'])
|
tdir = os.path.join(temp_path, instance['path'])
|
||||||
fork_job('calibre.srv.render_book', 'render_for_viewer', args=(
|
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},
|
path, tdir, {'size': instance['file_size'], 'mtime': instance['file_mtime'], 'hash': key},
|
||||||
), timeout=3000, no_output=True
|
)))
|
||||||
)
|
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
|
size = 0
|
||||||
for f in walk(tdir):
|
for f in walk(tdir):
|
||||||
size += os.path.getsize(f)
|
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__':
|
if __name__ == '__main__':
|
||||||
render_for_viewer(sys.argv[-2], sys.argv[-1], None)
|
render_for_viewer(sys.argv[-2], sys.argv[-1], None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user