mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-08 20:24:49 +02:00
Small optimization, only serialize common_data once instead of once per worker
This commit is contained in:
parent
c64828c6c8
commit
7be397aae6
1 changed files with 4 additions and 1 deletions
|
|
@ -72,6 +72,7 @@ def __init__(self, max_workers=None, name=None):
|
|||
self.tracker = Queue()
|
||||
self.terminal_failure = None
|
||||
self.common_data = None
|
||||
self.worker_data = None
|
||||
|
||||
self.start()
|
||||
|
||||
|
|
@ -80,7 +81,7 @@ def create_worker(self):
|
|||
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, cPickle.dumps((self.address, self.auth_key, self.common_data), -1))
|
||||
eintr_retry_call(p.stdin.write, self.worker_data)
|
||||
p.stdin.flush(), p.stdin.close()
|
||||
conn = eintr_retry_call(self.listener.accept)
|
||||
return Worker(p, conn, self.events, self.name)
|
||||
|
|
@ -94,6 +95,7 @@ def set_common_data(self, data=None):
|
|||
sent to workers.'''
|
||||
with self.lock:
|
||||
self.common_data = data
|
||||
self.worker_data = cPickle.dumps((self.address, self.auth_key, self.common_data), -1)
|
||||
for worker in self.available_workers:
|
||||
try:
|
||||
worker.set_common_data(data)
|
||||
|
|
@ -116,6 +118,7 @@ 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, self.common_data), -1)
|
||||
with self.lock:
|
||||
if self.start_worker() is False:
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in a new issue