def _recv(source): if not source in _recv.locks: _recv.locks[source] = thread.allocate_lock() with _recv.locks[source]: try: return cPickle.load(source) except (ValueError, cPickle.UnpicklingError), e: return messages.Unloadable(str(e)) except Exception, e: return messages.Unloadable("load error %s: %s" % (type(e).__name__, e))
def _recv(source): if not source in _recv.locks: _recv.locks[source] = thread.allocate_lock() with _recv.locks[source]: try: return cPickle.load(source) except (ValueError, cPickle.UnpicklingError), e: return messages.Unloadable(str(e)) except EOFError: raise
def _recv_with_info(source, acquire_recv_lock=True): """returns the first payload message from source that may/may not be preceded by Data_info """ if acquire_recv_lock: _acquire_recv_lock(source) try: msg = _recv(source, False) if not isinstance(msg, messages.Data_info): return msg data = source.read(msg.data_length) if len(data) != msg.data_length: raise EOFError() if "compressed(" in msg.data_format: data = zlib.decompress(data) try: return cPickle.loads(data) except (ValueError, cPickle.UnpicklingError), e: return messages.Unloadable(str(e)) except Exception, e: return messages.Unloadable("load error %s: %s" % (type(e).__name__, e))
def _recv(source, acquire_recv_lock=True): """returns the first message from source""" if acquire_recv_lock: _acquire_recv_lock(source) try: try: return cPickle.load(source) except (ValueError, cPickle.UnpicklingError), e: return messages.Unloadable(str(e)) except EOFError: raise except socket.error, e: raise EOFError("socket.error: " + str(e))
_send.locks = {} def _recv(source): if not source in _recv.locks: _recv.locks[source] = thread.allocate_lock() with _recv.locks[source]: try: return cPickle.load(source) except (ValueError, cPickle.UnpicklingError), e: return messages.Unloadable(str(e)) except EOFError: raise except Exception, e: return messages.Unloadable("load error %s: %s" % (type(e).__name__, e)) _recv.locks = {} _g_hooks = {} def _check_hook(signature, context): """Check if callbacks have been registered for a signature. If so, call them with the context""" if _g_hooks and signature in _g_hooks: for callback in _g_hooks[signature]: callback(signature, context)