diff --git a/src/calibre/debug.py b/src/calibre/debug.py index 24f727475b..0b4d2b252e 100644 --- a/src/calibre/debug.py +++ b/src/calibre/debug.py @@ -18,9 +18,10 @@ from polyglot.builtins import exec_path def run_calibre_debug(*args, **kw): import subprocess creationflags = 0 + headless = bool(kw.pop('headless', False)) if iswindows: creationflags = subprocess.CREATE_NO_WINDOW - cmd = get_debug_executable() + list(args) + cmd = get_debug_executable(headless=headless) + list(args) kw['creationflags'] = creationflags return subprocess.Popen(cmd, **kw) diff --git a/src/calibre/startup.py b/src/calibre/startup.py index 4e31a9c6af..32b4b6625d 100644 --- a/src/calibre/startup.py +++ b/src/calibre/startup.py @@ -22,10 +22,15 @@ builtins.__dict__['dynamic_property'] = lambda func: func(None) from calibre.constants import iswindows, ismacos, islinux, DEBUG, isfreebsd -def get_debug_executable(): +def get_debug_executable(headless=False): exe_name = 'calibre-debug' + ('.exe' if iswindows else '') if hasattr(sys, 'frameworks_dir'): base = os.path.dirname(sys.frameworks_dir) + if headless: + from calibre.utils.ipc.launch import Worker + class W(Worker): + exe_name = 'calibre-debug' + return [W().executable] return [os.path.join(base, 'MacOS', exe_name)] if getattr(sys, 'run_local', None): return [sys.run_local, exe_name] diff --git a/src/calibre/utils/ipc/launch.py b/src/calibre/utils/ipc/launch.py index 7fdf1889df..ba81f92387 100644 --- a/src/calibre/utils/ipc/launch.py +++ b/src/calibre/utils/ipc/launch.py @@ -140,11 +140,10 @@ class Worker: except: pass - def __init__(self, env, gui=False, job_name=None): - self._env = {} + def __init__(self, env=None, gui=False, job_name=None): self.gui = gui self.job_name = job_name - self._env = env.copy() + self._env = (env or {}).copy() def __call__(self, redirect_output=True, cwd=None, priority=None, pass_fds=()): ''' diff --git a/src/calibre/utils/rapydscript.py b/src/calibre/utils/rapydscript.py index 85f9842871..1933808ec2 100644 --- a/src/calibre/utils/rapydscript.py +++ b/src/calibre/utils/rapydscript.py @@ -233,7 +233,7 @@ def forked_compile(): def run_forked_compile(data, options): from calibre.debug import run_calibre_debug p = run_calibre_debug('-c', 'from calibre.utils.rapydscript import *; forked_compile()', - json.dumps(options), stdin=subprocess.PIPE, stdout=subprocess.PIPE) + json.dumps(options), stdin=subprocess.PIPE, stdout=subprocess.PIPE, headless=True) stdout = p.communicate(as_bytes(data))[0] if p.wait() != 0: raise SystemExit(p.returncode)