def work(self, socket, call, args, kwargs, topics=()): """Calls a function and send results to the collector. It supports all of function actions. A function could return, yield, raise any packable objects. """ task_id = uuid4_bytes() reply_socket, topics = self.replier(socket, topics, call.reply_to) if reply_socket: channel = (call.call_id, task_id, topics) else: channel = (None, None, None) f, rpc_spec = self.find_call_target(call) if rpc_spec.reject_if.__get__(self.app)(call, topics): reply_socket and self.reject(reply_socket, call.call_id, topics) return reply_socket and self.accept(reply_socket, channel) success = False with self.catch_exceptions(): try: val = self.call(call, args, kwargs, f, rpc_spec) except: exc_info = sys.exc_info() self.raise_(reply_socket, channel, exc_info) reraise(*exc_info) success = True if not success: # catch_exceptions() hides exceptions. return if isinstance(val, Iterator): vals = val with self.catch_exceptions(): try: try: val = next(vals) except StopIteration: pass else: self.send_reply(reply_socket, YIELD, val, *channel) for val in vals: self.send_reply(reply_socket, YIELD, val, *channel) self.send_reply(reply_socket, BREAK, None, *channel) except: exc_info = sys.exc_info() self.raise_(reply_socket, channel, exc_info) reraise(*exc_info) else: self.send_reply(reply_socket, RETURN, val, *channel)
def _call_wait(self, hints, name, args, kwargs, topics=(), raw=False, limit=None, retry=False, max_retries=None): """Allocates a call id and emit.""" col = self.collector if not col.is_running(): col.start() call_id = uuid4_bytes() reply_to = (DUPLEX if self.socket is col.socket else col.topic) # Normal tuple is faster than namedtuple. header = self._make_header(name, call_id, reply_to, hints) payload = self._pack(args, kwargs, raw) # Use short names. def send_call(): try: safe(send, self.socket, header, payload, topics, zmq.NOBLOCK) except zmq.Again: raise Undelivered('emission was not delivered') col.prepare(call_id, self, name, args, kwargs) send_call() return col.establish(call_id, self.timeout, limit, send_call if retry else None, max_retries=max_retries)
def test_basic_sanity_uuid4(self): buf = set() for _ in xrange(10000): u = libuuid.uuid4_bytes() self.assert_(u not in buf) buf.add(u)
def test_uuid4_bytes(self): b = libuuid.uuid4_bytes() self.assertEquals(type(b), str) self.assertEquals(uuid.UUID(bytes=b).version, 4)
def test_basic_sanity_uuid4(self): buf = set() for _ in range(10000): u = libuuid.uuid4_bytes() self.assert_(u not in buf) buf.add(u)
def test_uuid4_bytes(self): b = libuuid.uuid4_bytes() self.assertEquals(type(b), bytes) self.assertEquals(uuid.UUID(bytes=b).version, 4)