mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: More IPC fixes
This commit is contained in:
parent
a3c2f867f1
commit
7f4728e29c
@ -13,7 +13,7 @@ from calibre.constants import iswindows, isosx, isfrozen, filesystem_encoding, i
|
|||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
from calibre.ptempfile import PersistentTemporaryFile, base_dir
|
from calibre.ptempfile import PersistentTemporaryFile, base_dir
|
||||||
from calibre.utils.serialize import msgpack_dumps
|
from calibre.utils.serialize import msgpack_dumps
|
||||||
from polyglot.builtins import iteritems, unicode_type, string_or_bytes, environ_item
|
from polyglot.builtins import iteritems, unicode_type, string_or_bytes, environ_item, native_string_type
|
||||||
from polyglot.binary import as_hex_unicode
|
from polyglot.binary import as_hex_unicode
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
@ -111,9 +111,9 @@ class Worker(object):
|
|||||||
env[key] = val
|
env[key] = val
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
env[str('CALIBRE_WORKER')] = environ_item('1')
|
env[native_string_type('CALIBRE_WORKER')] = environ_item('1')
|
||||||
td = as_hex_unicode(msgpack_dumps(base_dir()))
|
td = as_hex_unicode(msgpack_dumps(base_dir()))
|
||||||
env[str('CALIBRE_WORKER_TEMP_DIR')] = environ_item(td)
|
env[native_string_type('CALIBRE_WORKER_TEMP_DIR')] = environ_item(td)
|
||||||
env.update(self._env)
|
env.update(self._env)
|
||||||
return env
|
return env
|
||||||
|
|
||||||
@ -161,19 +161,22 @@ class Worker(object):
|
|||||||
self._env = {}
|
self._env = {}
|
||||||
self.gui = gui
|
self.gui = gui
|
||||||
self.job_name = job_name
|
self.job_name = job_name
|
||||||
# Windows cannot handle unicode env vars
|
if ispy3:
|
||||||
for k, v in iteritems(env):
|
self._env = env.copy()
|
||||||
try:
|
else:
|
||||||
if isinstance(k, unicode_type):
|
# Windows cannot handle unicode env vars
|
||||||
k = k.encode('ascii')
|
for k, v in iteritems(env):
|
||||||
if isinstance(v, unicode_type):
|
try:
|
||||||
try:
|
if isinstance(k, unicode_type):
|
||||||
v = v.encode(filesystem_encoding)
|
k = k.encode('ascii')
|
||||||
except:
|
if isinstance(v, unicode_type):
|
||||||
v = v.encode('utf-8')
|
try:
|
||||||
self._env[k] = v
|
v = v.encode(filesystem_encoding)
|
||||||
except:
|
except:
|
||||||
pass
|
v = v.encode('utf-8')
|
||||||
|
self._env[k] = v
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def __call__(self, redirect_output=True, cwd=None, priority=None):
|
def __call__(self, redirect_output=True, cwd=None, priority=None):
|
||||||
'''
|
'''
|
||||||
@ -187,7 +190,7 @@ class Worker(object):
|
|||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
# cwd no longer exists
|
# cwd no longer exists
|
||||||
origwd = cwd or os.path.expanduser(u'~')
|
origwd = cwd or os.path.expanduser(u'~')
|
||||||
env[str('ORIGWD')] = environ_item(as_hex_unicode(msgpack_dumps(origwd)))
|
env[native_string_type('ORIGWD')] = environ_item(as_hex_unicode(msgpack_dumps(origwd)))
|
||||||
_cwd = cwd
|
_cwd = cwd
|
||||||
if priority is None:
|
if priority is None:
|
||||||
priority = prefs['worker_process_priority']
|
priority = prefs['worker_process_priority']
|
||||||
|
@ -221,8 +221,7 @@ class Server(Thread):
|
|||||||
redirect_output = not gui
|
redirect_output = not gui
|
||||||
|
|
||||||
env = {
|
env = {
|
||||||
'CALIBRE_WORKER_ADDRESS' : environ_item(as_hex_unicode(msgpack_dumps(
|
'CALIBRE_WORKER_ADDRESS' : environ_item(as_hex_unicode(msgpack_dumps(self.address))),
|
||||||
self.listener.address))),
|
|
||||||
'CALIBRE_WORKER_KEY' : environ_item(as_hex_unicode(self.auth_key)),
|
'CALIBRE_WORKER_KEY' : environ_item(as_hex_unicode(self.auth_key)),
|
||||||
'CALIBRE_WORKER_RESULT' : environ_item(as_hex_unicode(rfile)),
|
'CALIBRE_WORKER_RESULT' : environ_item(as_hex_unicode(rfile)),
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ def create_worker(env, priority='normal', cwd=None, func='main'):
|
|||||||
|
|
||||||
env = dict(env)
|
env = dict(env)
|
||||||
env.update({
|
env.update({
|
||||||
'CALIBRE_WORKER_ADDRESS': environ_item(as_hex_unicode(msgpack_dumps(listener.address))),
|
'CALIBRE_WORKER_ADDRESS': environ_item(as_hex_unicode(msgpack_dumps(address))),
|
||||||
'CALIBRE_WORKER_KEY': environ_item(as_hex_unicode(auth_key)),
|
'CALIBRE_WORKER_KEY': environ_item(as_hex_unicode(auth_key)),
|
||||||
'CALIBRE_SIMPLE_WORKER': environ_item('calibre.utils.ipc.simple_worker:%s' % func),
|
'CALIBRE_SIMPLE_WORKER': environ_item('calibre.utils.ipc.simple_worker:%s' % func),
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user