mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Replace use of pickle for the editor completion worker
This commit is contained in:
parent
fc61fc88bc
commit
1e6d9e9583
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import cPickle, os, sys
|
||||
import os, sys
|
||||
from threading import Thread, Event, RLock
|
||||
from Queue import Queue
|
||||
from contextlib import closing
|
||||
@ -16,6 +16,7 @@ from calibre.constants import iswindows
|
||||
from calibre.gui2.tweak_book.completion.basic import Request
|
||||
from calibre.gui2.tweak_book.completion.utils import DataError
|
||||
from calibre.utils.ipc import eintr_retry_call
|
||||
from calibre.utils.serialize import msgpack_loads, msgpack_dumps
|
||||
|
||||
COMPLETION_REQUEST = 'completion request'
|
||||
CLEAR_REQUEST = 'clear request'
|
||||
@ -46,7 +47,7 @@ class CompletionWorker(Thread):
|
||||
'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))
|
||||
eintr_retry_call(p.stdin.write, msgpack_dumps((address, auth_key)))
|
||||
p.stdin.flush(), p.stdin.close()
|
||||
self.control_conn = eintr_retry_call(self.listener.accept)
|
||||
self.data_conn = eintr_retry_call(self.listener.accept)
|
||||
@ -172,7 +173,8 @@ def completion_worker():
|
||||
|
||||
def run_main(func):
|
||||
from multiprocessing.connection import Client
|
||||
address, key = cPickle.loads(eintr_retry_call(sys.stdin.read))
|
||||
stdin = getattr(sys.stdin, 'buffer', sys.stdin)
|
||||
address, key = msgpack_loads(eintr_retry_call(stdin.read))
|
||||
with closing(Client(address, authkey=key)) as control_conn, closing(Client(address, authkey=key)) as data_conn:
|
||||
func(control_conn, data_conn)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user