[Zodb-checkins] CVS: StandaloneZODB/ZEO - zrpc2.py:1.1.2.21
Jeremy Hylton
jeremy@zope.com
Fri, 4 Jan 2002 18:06:49 -0500
Update of /cvs-repository/StandaloneZODB/ZEO
In directory cvs.zope.org:/tmp/cvs-serv24784
Modified Files:
Tag: ZEO-ZRPC-Dev
zrpc2.py
Log Message:
Remove option of passing pickler object to Marshaller. (YAGNI)
Add try/except to deal with harmless race for synchronous connect()
call.
=== StandaloneZODB/ZEO/zrpc2.py 1.1.2.20 => 1.1.2.21 ===
return c
-# We create a special fast pickler! This allows us
-# to create slightly more efficient pickles and
-# to create them a tad faster.
-pickler = cPickle.Pickler()
-pickler.fast = 1 # Don't use the memo
-dump = pickler.dump
-
class Marshaller:
"""Marshal requests and replies to second across network"""
- def __init__(self, pickle=None):
- if pickle is not None:
- self.pickle = pickle
- self.errors = pickle.PickleError
- else:
- self.pickle = cPickle.Pickler().dump
- self.errors = (cPickle.UnpickleableError,
- cPickle.UnpicklingError,
- cPickle.PickleError,
- cPickle.PicklingError)
+ # It's okay to share a single Pickler as long as it's in fast
+ # mode, which means that it doesn't have a memo.
+
+ pickler = cPickle.Pickler()
+ pickler.fast = 1
+ pickle = pickler.dump
+
+ errors = (cPickle.UnpickleableError,
+ cPickle.UnpicklingError,
+ cPickle.PickleError,
+ cPickle.PicklingError)
def encode(self, msgid, flags, name, args):
"""Returns an encoded message"""
@@ -105,7 +99,6 @@
try:
return unpickler.load() # msgid, flags, name, args
- msgid, flags, name, args = unpickler.load()
except (cPickle.UnpicklingError, IndexError), err_msg:
log("can't decode %s" % repr(msg), level=zLOG.ERROR)
raise DecodingError(msg)
@@ -143,10 +136,10 @@
__super_close = smac.SizedMessageAsyncConnection.close
__super_writable = smac.SizedMessageAsyncConnection.writable
- def __init__(self, sock, addr, obj=None, pickle=None):
+ def __init__(self, sock, addr, obj=None):
self.msgid = 0
self.obj = obj
- self.marshal = Marshaller(pickle)
+ self.marshal = Marshaller()
self.closed = 0
self.async = 0
# The reply lock is used to block when a synchronous call is
@@ -325,7 +318,7 @@
if self.closed:
raise DisconnectedError("This action is temporarily unavailable")
msgid = self.msgid
- self.msgid = self.msgid + 1
+ self.msgid += 1
if __debug__:
log("send msg: %d, %d, %s, ..." % (msgid, ASYNC, method))
self.message_output(self.marshal.encode(msgid, ASYNC, method, args))
@@ -437,10 +430,14 @@
self._thread = threading.Thread(target=self.__connect,
args=(1,))
self._thread.start()
+ if sync:
+ try:
+ self._thread.join()
+ except AttributeError:
+ # probably means the thread exited quickly
+ pass
finally:
self._connect_lock.release()
- if sync and self._thread is not None:
- self._thread.join()
def attempt_connect(self):
self.__connect(repeat=0)
@@ -514,9 +511,9 @@
__super_init = Connection.__init__
__super_close = Connection.close
- def __init__(self, sock, addr, obj, mgr, pickle=None):
+ def __init__(self, sock, addr, obj, mgr):
self.__mgr = mgr
- self.__super_init(sock, addr, obj, pickle)
+ self.__super_init(sock, addr, obj)
def close(self):
self.__super_close()
@@ -531,14 +528,14 @@
__super_init = Connection.__init__
__super_close = Connection.close
- def __init__(self, sock, addr, obj, mgr, pickle=None):
+ def __init__(self, sock, addr, obj, mgr):
self.__mgr = mgr
if self.__mgr.async:
self.__async = 1
self.trigger = self.__mgr.trigger
else:
self.__async = None
- self.__super_init(sock, addr, obj, pickle)
+ self.__super_init(sock, addr, obj)
def _prepare_async(self):
# Don't do the register_loop_callback that the superclass does