mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont use pickle to pass temp dir to worker processes
This commit is contained in:
parent
7e670497eb
commit
74497a4ff8
@ -105,10 +105,11 @@ def base_dir():
|
|||||||
if _base_dir is None:
|
if _base_dir is None:
|
||||||
td = os.environ.get('CALIBRE_WORKER_TEMP_DIR', None)
|
td = os.environ.get('CALIBRE_WORKER_TEMP_DIR', None)
|
||||||
if td is not None:
|
if td is not None:
|
||||||
import cPickle, binascii
|
import binascii
|
||||||
|
from calibre.utils.serialize import msgpack_loads
|
||||||
try:
|
try:
|
||||||
td = cPickle.loads(binascii.unhexlify(td))
|
td = msgpack_loads(binascii.unhexlify(td))
|
||||||
except:
|
except Exception:
|
||||||
td = None
|
td = None
|
||||||
if td and os.path.exists(td):
|
if td and os.path.exists(td):
|
||||||
_base_dir = td
|
_base_dir = td
|
||||||
|
@ -6,12 +6,13 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import subprocess, os, sys, time, binascii, cPickle
|
import subprocess, os, sys, time, binascii
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from calibre.constants import iswindows, isosx, isfrozen, filesystem_encoding
|
from calibre.constants import iswindows, isosx, isfrozen, filesystem_encoding
|
||||||
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 polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
@ -104,9 +105,9 @@ class Worker(object):
|
|||||||
env[key] = val
|
env[key] = val
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
env[b'CALIBRE_WORKER'] = b'1'
|
env[str('CALIBRE_WORKER')] = str('1')
|
||||||
td = binascii.hexlify(cPickle.dumps(base_dir()))
|
td = binascii.hexlify(msgpack_dumps(base_dir())).decode('ascii')
|
||||||
env[b'CALIBRE_WORKER_TEMP_DIR'] = bytes(td)
|
env[b'CALIBRE_WORKER_TEMP_DIR'] = str(td)
|
||||||
env.update(self._env)
|
env.update(self._env)
|
||||||
return env
|
return env
|
||||||
|
|
||||||
@ -176,13 +177,11 @@ class Worker(object):
|
|||||||
exe = self.gui_executable if self.gui else self.executable
|
exe = self.gui_executable if self.gui else self.executable
|
||||||
env = self.env
|
env = self.env
|
||||||
try:
|
try:
|
||||||
env[b'ORIGWD'] = binascii.hexlify(cPickle.dumps(
|
origwd = cwd or os.path.abspath(os.getcwdu())
|
||||||
cwd or os.path.abspath(os.getcwdu())))
|
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
# cwd no longer exists
|
# cwd no longer exists
|
||||||
env[b'ORIGWD'] = binascii.hexlify(cPickle.dumps(
|
origwd = cwd or os.path.expanduser(u'~')
|
||||||
cwd or os.path.expanduser(u'~')))
|
env[str('ORIGWD')] = binascii.hexlify(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']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user