mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ensure worker env keys are bytes/unicodeon py2/3
This commit is contained in:
parent
e73e782b56
commit
dbcb63c290
@ -27,7 +27,7 @@ from calibre.utils.ipc import eintr_retry_call
|
||||
from calibre.utils.ipc.launch import Worker
|
||||
from calibre.utils.ipc.worker import PARALLEL_FUNCS
|
||||
from calibre.utils.serialize import msgpack_dumps, pickle_loads
|
||||
from polyglot.builtins import string_or_bytes
|
||||
from polyglot.builtins import string_or_bytes, environ_item
|
||||
|
||||
|
||||
_counter = 0
|
||||
@ -219,9 +219,10 @@ class Server(Thread):
|
||||
redirect_output = not gui
|
||||
|
||||
env = {
|
||||
'CALIBRE_WORKER_ADDRESS' : hexlify(msgpack_dumps(self.listener.address)),
|
||||
'CALIBRE_WORKER_KEY' : hexlify(self.auth_key),
|
||||
'CALIBRE_WORKER_RESULT' : hexlify(rfile.encode('utf-8')),
|
||||
'CALIBRE_WORKER_ADDRESS' : environ_item(hexlify(msgpack_dumps(
|
||||
self.listener.address))),
|
||||
'CALIBRE_WORKER_KEY' : environ_item(hexlify(self.auth_key)),
|
||||
'CALIBRE_WORKER_RESULT' : environ_item(hexlify(rfile.encode('utf-8'))),
|
||||
}
|
||||
cw = self.do_launch(env, gui, redirect_output, rfile, job_name=job_name)
|
||||
if isinstance(cw, string_or_bytes):
|
||||
|
@ -17,7 +17,7 @@ from calibre.constants import iswindows
|
||||
from calibre.utils.ipc import eintr_retry_call
|
||||
from calibre.utils.ipc.launch import Worker
|
||||
from calibre.utils.serialize import msgpack_loads, msgpack_dumps
|
||||
from polyglot.builtins import unicode_type, string_or_bytes
|
||||
from polyglot.builtins import unicode_type, string_or_bytes, environ_item
|
||||
|
||||
|
||||
class WorkerError(Exception):
|
||||
@ -131,9 +131,9 @@ def create_worker(env, priority='normal', cwd=None, func='main'):
|
||||
|
||||
env = dict(env)
|
||||
env.update({
|
||||
'CALIBRE_WORKER_ADDRESS': hexlify(msgpack_dumps(listener.address)),
|
||||
'CALIBRE_WORKER_KEY': hexlify(auth_key),
|
||||
'CALIBRE_SIMPLE_WORKER': 'calibre.utils.ipc.simple_worker:%s' % func,
|
||||
'CALIBRE_WORKER_ADDRESS': environ_item(hexlify(msgpack_dumps(listener.address))),
|
||||
'CALIBRE_WORKER_KEY': environ_item(hexlify(auth_key)),
|
||||
'CALIBRE_SIMPLE_WORKER': environ_item('calibre.utils.ipc.simple_worker:%s' % func),
|
||||
})
|
||||
|
||||
w = Worker(env)
|
||||
|
@ -40,6 +40,10 @@ if is_py3:
|
||||
def iterkeys(d):
|
||||
return iter(d)
|
||||
|
||||
def environ_item(x):
|
||||
if isinstance(x, bytes):
|
||||
x = x.decode('utf-8')
|
||||
return x
|
||||
else:
|
||||
exec("""def reraise(tp, value, tb=None):
|
||||
try:
|
||||
@ -64,3 +68,8 @@ else:
|
||||
|
||||
def itervalues(d):
|
||||
return d.itervalues()
|
||||
|
||||
def environ_item(x):
|
||||
if isinstance(x, unicode_type):
|
||||
x = x.encode('utf-8')
|
||||
return x
|
||||
|
Loading…
x
Reference in New Issue
Block a user