mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Allow launching of calibre worker process in-tree
This commit is contained in:
parent
bcfa99cb13
commit
ee3fdcba3d
@ -16,10 +16,12 @@ isnetbsd = 'netbsd' in sys.platform
|
|||||||
isdragonflybsd = 'dragonfly' in sys.platform
|
isdragonflybsd = 'dragonfly' in sys.platform
|
||||||
isbsd = isnetbsd or isfreebsd or isdragonflybsd
|
isbsd = isnetbsd or isfreebsd or isdragonflybsd
|
||||||
islinux = not isosx and not iswindows and not isbsd
|
islinux = not isosx and not iswindows and not isbsd
|
||||||
SRC = os.path.abspath('src')
|
sys.setup_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
SRC = os.path.abspath(os.path.join(os.path.dirname(sys.setup_dir), 'src'))
|
||||||
sys.path.insert(0, SRC)
|
sys.path.insert(0, SRC)
|
||||||
sys.resources_location = os.path.join(os.path.dirname(SRC), 'resources')
|
sys.resources_location = os.path.join(os.path.dirname(SRC), 'resources')
|
||||||
sys.extensions_location = os.path.join(SRC, 'calibre', 'plugins')
|
sys.extensions_location = os.path.join(SRC, 'calibre', 'plugins')
|
||||||
|
sys.running_from_setup = True
|
||||||
|
|
||||||
__version__ = __appname__ = modules = functions = basenames = scripts = None
|
__version__ = __appname__ = modules = functions = basenames = scripts = None
|
||||||
|
|
||||||
|
17
setup/run-calibre-worker.py
Normal file
17
setup/run-calibre-worker.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# vim:fileencoding=utf-8
|
||||||
|
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import,
|
||||||
|
print_function)
|
||||||
|
import sys, os
|
||||||
|
sys.setup_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
SRC = os.path.abspath(os.path.join(os.path.dirname(sys.setup_dir), 'src'))
|
||||||
|
sys.path.insert(0, SRC)
|
||||||
|
sys.resources_location = os.path.join(os.path.dirname(SRC), 'resources')
|
||||||
|
sys.extensions_location = os.path.join(SRC, 'calibre', 'plugins')
|
||||||
|
sys.running_from_setup = True
|
||||||
|
|
||||||
|
from calibre.utils.ipc.worker import main
|
||||||
|
print(111111111111)
|
||||||
|
sys.exit(main())
|
@ -55,6 +55,8 @@ class Worker(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def executable(self):
|
def executable(self):
|
||||||
|
if hasattr(sys, 'running_from_setup'):
|
||||||
|
return [sys.executable, os.path.join(sys.setup_dir, 'run-calibre-worker.py')]
|
||||||
e = self.exe_name
|
e = self.exe_name
|
||||||
if iswindows:
|
if iswindows:
|
||||||
return os.path.join(os.path.dirname(sys.executable),
|
return os.path.join(os.path.dirname(sys.executable),
|
||||||
@ -73,7 +75,7 @@ class Worker(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def gui_executable(self):
|
def gui_executable(self):
|
||||||
if isosx:
|
if isosx and not hasattr(sys, 'running_from_setup'):
|
||||||
if self.job_name in {'ebook-viewer', 'ebook-edit'}:
|
if self.job_name in {'ebook-viewer', 'ebook-edit'}:
|
||||||
return self.executable.replace('/console.app/', '/%s.app/' % self.job_name)
|
return self.executable.replace('/console.app/', '/%s.app/' % self.job_name)
|
||||||
return os.path.join(sys.binaries_path, self.exe_name)
|
return os.path.join(sys.binaries_path, self.exe_name)
|
||||||
@ -181,7 +183,7 @@ class Worker(object):
|
|||||||
_cwd = cwd
|
_cwd = cwd
|
||||||
if priority is None:
|
if priority is None:
|
||||||
priority = prefs['worker_process_priority']
|
priority = prefs['worker_process_priority']
|
||||||
cmd = [exe]
|
cmd = [exe] if isinstance(exe, basestring) else exe
|
||||||
args = {
|
args = {
|
||||||
'env' : env,
|
'env' : env,
|
||||||
'cwd' : _cwd,
|
'cwd' : _cwd,
|
||||||
|
@ -123,11 +123,9 @@ def create_worker(env, priority='normal', cwd=None, func='main'):
|
|||||||
|
|
||||||
env = dict(env)
|
env = dict(env)
|
||||||
env.update({
|
env.update({
|
||||||
'CALIBRE_WORKER_ADDRESS' :
|
'CALIBRE_WORKER_ADDRESS': hexlify(cPickle.dumps(listener.address, -1)),
|
||||||
hexlify(cPickle.dumps(listener.address, -1)),
|
'CALIBRE_WORKER_KEY': hexlify(auth_key),
|
||||||
'CALIBRE_WORKER_KEY' : hexlify(auth_key),
|
'CALIBRE_SIMPLE_WORKER': 'calibre.utils.ipc.simple_worker:%s' % func,
|
||||||
'CALIBRE_SIMPLE_WORKER':
|
|
||||||
'calibre.utils.ipc.simple_worker:%s' % func,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
w = Worker(env)
|
w = Worker(env)
|
||||||
@ -157,7 +155,9 @@ def start_pipe_worker(command, env=None, priority='normal', **process_args):
|
|||||||
args['preexec_fn'] = partial(renice, niceness)
|
args['preexec_fn'] = partial(renice, niceness)
|
||||||
args['close_fds'] = True
|
args['close_fds'] = True
|
||||||
|
|
||||||
p = subprocess.Popen([w.executable, '--pipe-worker', command], **args)
|
exe = w.executable
|
||||||
|
cmd = [exe] if isinstance(exe, basestring) else exe
|
||||||
|
p = subprocess.Popen(cmd + ['--pipe-worker', command], **args)
|
||||||
return p
|
return p
|
||||||
|
|
||||||
def fork_job(mod_name, func_name, args=(), kwargs={}, timeout=300, # seconds
|
def fork_job(mod_name, func_name, args=(), kwargs={}, timeout=300, # seconds
|
||||||
|
Loading…
x
Reference in New Issue
Block a user