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): from calibre.utils.ipc.server import create_listener self.auth_key = os.urandom(32) self.address, self.listener = create_listener(self.auth_key) self.worker_data = cPickle.dumps((self.address, self.auth_key), -1) if self.start_worker() is False: return while True: event = self.events.get() if event is None or self.shutting_down: break if self.handle_event(event) is False: break
def launch_worker_process(self): from calibre.utils.ipc.server import create_listener from calibre.utils.ipc.pool import start_worker self.worker_process = p = start_worker( 'from {0} import run_main, {1}; run_main({1})'.format(self.__class__.__module__, self.worker_entry_point)) 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.data_thread = t = Thread(name='CWData', target=self.handle_data_requests) t.daemon = True t.start() self.connected.set()
def create_worker(env, priority='normal', cwd=None, func='main'): from calibre.utils.ipc.server import create_listener auth_key = os.urandom(32) address, listener = create_listener(auth_key) env = dict(env) env.update({ 'CALIBRE_WORKER_ADDRESS': hexlify(cPickle.dumps(listener.address, -1)), 'CALIBRE_WORKER_KEY': hexlify(auth_key), 'CALIBRE_SIMPLE_WORKER': 'calibre.utils.ipc.simple_worker:%s' % func, }) w = Worker(env) w(cwd=cwd, priority=priority) return listener, w
def create_worker(env, priority='normal', cwd=None, func='main'): from calibre.utils.ipc.server import create_listener auth_key = os.urandom(32) address, listener = create_listener(auth_key) env = dict(env) env.update({ 'CALIBRE_WORKER_ADDRESS': environ_item(as_hex_unicode(msgpack_dumps(address))), 'CALIBRE_WORKER_KEY': environ_item(as_hex_unicode(auth_key)), 'CALIBRE_SIMPLE_WORKER': environ_item('calibre.utils.ipc.simple_worker:%s' % func), }) w = Worker(env) w(cwd=cwd, priority=priority) return listener, w
def create_worker(env, priority='normal', cwd=None, func='main'): from calibre.utils.ipc.server import create_listener auth_key = os.urandom(32) address, listener = create_listener(auth_key) env = dict(env) env.update({ 'CALIBRE_WORKER_ADDRESS' : hexlify(cPickle.dumps(listener.address, -1)), 'CALIBRE_WORKER_KEY' : hexlify(auth_key), 'CALIBRE_SIMPLE_WORKER': 'calibre.utils.ipc.simple_worker:%s' % func, }) w = Worker(env) w(cwd=cwd, priority=priority) return listener, w