def start_recycler(): global recycler if recycler is None: from calibre.utils.ipc.simple_worker import start_pipe_worker recycler = start_pipe_worker( 'from calibre.utils.recycle_bin import recycler_main; recycler_main()' )
def do_convert(path, temp_path, key, instance): tdir = os.path.join(temp_path, instance['path']) p = None try: with TemporaryFile('log.txt') as logpath: with open(logpath, 'w+b') as logf: p = start_pipe_worker( 'from calibre.srv.render_book import viewer_main; viewer_main()', stdout=logf, stderr=logf) running_workers.append(p) p.stdin.write( msgpack_dumps(( path, tdir, { 'size': instance['file_size'], 'mtime': instance['file_mtime'], 'hash': key }, ))) p.stdin.close() if p.wait() != 0: with lopen(logpath, 'rb') as logf: worker_output = logf.read().decode('utf-8', 'replace') raise ConversionFailure(path, worker_output) finally: try: running_workers.remove(p) except Exception: pass size = 0 for f in walk(tdir): size += os.path.getsize(f) instance['cache_size'] = size
def launch_worker(self): with lopen(os.path.join(self.tdir, '{}.json'.format(len(self.workers))), 'wb') as output: error = lopen(os.path.join(self.tdir, '{}.error'.format(len(self.workers))), 'wb') p = start_pipe_worker('from calibre.srv.render_book import worker_main; worker_main()', stdout=error, stderr=error) p.output_path = output.name p.error_path = error.name self.workers.append(p)
def launch_process(self, debug_executable): from calibre.utils.ipc.simple_worker import start_pipe_worker if DEBUG: args = {'stdout':None, 'stderr': None} else: args = {'stdout':open(os.devnull, 'wb'), 'stderr':subprocess.STDOUT} self.process = start_pipe_worker('from calibre.gui2.splash import main; main()', **args)
def start_worker(code, name=''): from calibre.utils.ipc.simple_worker import start_pipe_worker if name: name = '-' + name p = start_pipe_worker(code, **worker_kwargs) if get_stdout_from_child: t = Thread(target=get_stdout, name='PoolWorkerGetStdout' + name, args=(p,)) t.daemon = True t.start() return p
def worker_for_source(self, source): wname = f'{source}::{get_ident()}' with self.lock: ans = self.workers.get(wname) if ans is None: w = start_pipe_worker( f'from calibre.scraper.simple import worker_main; worker_main({source!r})' ) ans = self.workers[wname] = w return ans
def launch_process(self, debug_executable): from calibre.utils.ipc.simple_worker import start_pipe_worker if DEBUG: args = {'stdout': None, 'stderr': None} else: args = { 'stdout': open(os.devnull, 'wb'), 'stderr': subprocess.STDOUT } self.process = start_pipe_worker( 'from calibre.gui2.splash import main; main()', **args)
def create_worker(self): from calibre.utils.ipc.simple_worker import start_pipe_worker p = start_pipe_worker( 'from {0} import run_main, {1}; run_main({1})'.format(self.__class__.__module__, 'worker_main'), stdout=None) sys.stdout.flush() eintr_retry_call(p.stdin.write, self.worker_data) p.stdin.flush(), p.stdin.close() conn = eintr_retry_call(self.listener.accept) w = Worker(p, conn, self.events, self.name) if self.common_data != cPickle.dumps(None, -1): w.set_common_data(self.common_data) return w
def launch_worker_process(self): from calibre.utils.ipc.server import create_listener from calibre.utils.ipc.simple_worker import start_pipe_worker self.worker_process = p = start_pipe_worker( 'from {0} import run_main, {1}; run_main({1})'.format(self.__class__.__module__, self.worker_entry_point), stdout=None) auth_key = os.urandom(32) address, self.listener = create_listener(auth_key) eintr_retry_call(p.stdin.write, cPickle.dumps((address, auth_key), -1)) p.stdin.flush(), p.stdin.close() self.control_conn = eintr_retry_call(self.listener.accept) self.data_conn = eintr_retry_call(self.listener.accept) self.connected.set()
def run(self): try: with PersistentTemporaryFile('print-to-pdf-log.txt') as f: p = self.worker = start_pipe_worker('from calibre.gui2.viewer.printing import do_print; do_print()', stdout=f, stderr=subprocess.STDOUT) p.stdin.write(cPickle.dumps(self.data, -1)), p.stdin.flush(), p.stdin.close() rc = p.wait() if rc != 0: f.seek(0) self.log = f.read().decode('utf-8', 'replace') try: os.remove(f.name) except EnvironmentError: pass except Exception: import traceback self.tb = traceback.format_exc()
def run(self): try: with PersistentTemporaryFile('print-to-pdf-log.txt') as f: p = self.worker = start_pipe_worker('from calibre.gui2.viewer.printing import do_print; do_print()', stdout=f, stderr=subprocess.STDOUT) p.stdin.write(msgpack_dumps(self.data)), p.stdin.flush(), p.stdin.close() rc = p.wait() if rc != 0: f.seek(0) self.log = f.read().decode('utf-8', 'replace') try: os.remove(f.name) except EnvironmentError: pass except Exception: import traceback self.tb = traceback.format_exc()
def start_recycler(): global recycler if recycler is None: from calibre.utils.ipc.simple_worker import start_pipe_worker recycler = start_pipe_worker('from calibre.utils.recycle_bin import recycler_main; recycler_main()')