From cb9059c231df2cef57f92ef8e06725768373290f Mon Sep 17 00:00:00 2001 From: tamodolo Date: Sun, 3 Jan 2016 14:49:21 -0200 Subject: [PATCH] kindlegen is now forced to terminate A bug in kindlegen causes it randonly to hang when converting epub to mobi. This happens above 90% of the time it is called so this change foce it to be killed as soon kcc detects it's donne the job. For this to work shell arg must be false. Otherwise terminate() will try to kill the new opened cmd/terminal instead of kindlegen. --- kcc/comic2ebook.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 48c0fa9..8b6dd84 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -1226,8 +1226,9 @@ def makeMOBIWorker(item): kindlegenError = '' try: if os.path.getsize(item) < 629145600: + print("Creating MOBI file...") output = Popen('kindlegen -dont_append_source -locale en "' + item + '"', - stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True) + stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=False) for line in output.stdout: line = line.decode('utf-8') # ERROR: Generic error @@ -1239,6 +1240,8 @@ def makeMOBIWorker(item): kindlegenErrorCode = 23026 if kindlegenErrorCode > 0: break + if "Mobi file built successfully" in line: + output.terminate() else: # ERROR: EPUB too big kindlegenErrorCode = 23026