mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make calibre worker processes use the same temp directory as the calibre GUI
This commit is contained in:
parent
6a57e799af
commit
f9bddf4f67
@ -5,7 +5,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
Provides platform independent temporary files that persist even after
|
||||
being closed.
|
||||
"""
|
||||
import tempfile, os, atexit
|
||||
import tempfile, os, atexit, binascii, cPickle
|
||||
|
||||
from calibre import __version__, __appname__
|
||||
|
||||
@ -30,6 +30,15 @@ def remove_dir(x):
|
||||
def base_dir():
|
||||
global _base_dir
|
||||
if _base_dir is None:
|
||||
td = os.environ.get('CALIBRE_WORKER_TEMP_DIR', None)
|
||||
if td is not None:
|
||||
try:
|
||||
td = cPickle.loads(binascii.unhexlify(td))
|
||||
except:
|
||||
td = None
|
||||
if td and os.path.exists(td):
|
||||
_base_dir = td
|
||||
else:
|
||||
_base_dir = tempfile.mkdtemp(prefix='%s_%s_tmp_'%(__appname__,
|
||||
__version__))
|
||||
atexit.register(remove_dir, _base_dir)
|
||||
|
@ -6,11 +6,11 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import subprocess, os, sys, time
|
||||
import subprocess, os, sys, time, binascii, cPickle
|
||||
|
||||
from calibre.constants import iswindows, isosx, isfrozen, isnewosx
|
||||
from calibre.utils.config import prefs
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.ptempfile import PersistentTemporaryFile, base_dir
|
||||
|
||||
if iswindows:
|
||||
import win32process
|
||||
@ -81,6 +81,8 @@ class Worker(object):
|
||||
def env(self):
|
||||
env = dict(os.environ)
|
||||
env['CALIBRE_WORKER'] = '1'
|
||||
td = binascii.hexlify(cPickle.dumps(base_dir()))
|
||||
env['CALIBRE_WORKER_TEMP_DIR'] = td
|
||||
env.update(self._env)
|
||||
return env
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user