當前位置: 首頁>>代碼示例>>Python>>正文


Python zmq.SNDMORE屬性代碼示例

本文整理匯總了Python中zmq.SNDMORE屬性的典型用法代碼示例。如果您正苦於以下問題:Python zmq.SNDMORE屬性的具體用法?Python zmq.SNDMORE怎麽用?Python zmq.SNDMORE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在zmq的用法示例。


在下文中一共展示了zmq.SNDMORE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_unicode_sockopts

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def test_unicode_sockopts(self):
        """test setting/getting sockopts with unicode strings"""
        topic = "tést"
        if str is not unicode:
            topic = topic.decode('utf8')
        p,s = self.create_bound_pair(zmq.PUB, zmq.SUB)
        self.assertEqual(s.send_unicode, s.send_unicode)
        self.assertEqual(p.recv_unicode, p.recv_unicode)
        self.assertRaises(TypeError, s.setsockopt, zmq.SUBSCRIBE, topic)
        self.assertRaises(TypeError, s.setsockopt, zmq.IDENTITY, topic)
        s.setsockopt_unicode(zmq.IDENTITY, topic, 'utf16')
        self.assertRaises(TypeError, s.setsockopt, zmq.AFFINITY, topic)
        s.setsockopt_unicode(zmq.SUBSCRIBE, topic)
        self.assertRaises(TypeError, s.getsockopt_unicode, zmq.AFFINITY)
        self.assertRaisesErrno(zmq.EINVAL, s.getsockopt_unicode, zmq.SUBSCRIBE)
        
        identb = s.getsockopt(zmq.IDENTITY)
        identu = identb.decode('utf16')
        identu2 = s.getsockopt_unicode(zmq.IDENTITY, 'utf16')
        self.assertEqual(identu, identu2)
        time.sleep(0.1) # wait for connection/subscription
        p.send_unicode(topic,zmq.SNDMORE)
        p.send_unicode(topic*2, encoding='latin-1')
        self.assertEqual(topic, s.recv_unicode())
        self.assertEqual(topic*2, s.recv_unicode(encoding='latin-1')) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:27,代碼來源:test_socket.py

示例2: run

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def run(self):
        """
        Main execution.
        Returns:
        """
        # Socket to communicate with front facing server.
        socket = self.zmq_context.socket(zmq.DEALER)
        socket.connect('inproc://backend')

        while True:
            # First string recieved is socket ID of client
            client_id = socket.recv()
            request = socket.recv()
            # print('Worker ID - %s. Recieved computation request.' % (self.worker_id))

            result = self.compute(request)

            # print('Worker ID - %s. Sending computed result back.' % (self.worker_id))

            # For successful routing of result to correct client, the socket ID of client should be sent first.
            socket.send(client_id, zmq.SNDMORE)
            socket.send_string(result) 
開發者ID:amansrivastava17,項目名稱:embedding-as-service,代碼行數:24,代碼來源:__init__.py

示例3: fetch_tx

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def fetch_tx(self, testnet=False):
        if self.prev_tx not in self.cache:
            socket = self.get_socket(testnet=testnet)
            nonce = int_to_little_endian(random.randint(0, 2**32), 4)
            msg = b'blockchain.fetch_transaction2'
            socket.send(msg, zmq.SNDMORE)
            socket.send(nonce, zmq.SNDMORE)
            socket.send(self.prev_tx[::-1])
            response_msg = socket.recv()
            response_nonce = socket.recv()
            if response_msg != msg or response_nonce != nonce:
                raise RuntimeError('received wrong msg: {}'.format(
                    response_msg.decode('ascii')))
            response_tx = socket.recv()
            response_code = little_endian_to_int(response_tx[:4])
            if response_code != 0:
                raise RuntimeError('got code from server: {}'.format(response_code))
            stream = BytesIO(response_tx[4:])
            self.cache[self.prev_tx] = Tx.parse(stream)
        return self.cache[self.prev_tx] 
開發者ID:jimmysong,項目名稱:pybtcfork,代碼行數:22,代碼來源:tx.py

示例4: send_array

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def send_array(self, A, msg='NoName', flags=0, copy=True, track=False):
        """Sends a numpy array with metadata and text message.

        Sends a numpy array with the metadata necessary for reconstructing
        the array (dtype,shape). Also sends a text msg, often the array or
        image name.

        Arguments:
          A: numpy array or OpenCV image.
          msg: (optional) array name, image name or text message.
          flags: (optional) zmq flags.
          copy: (optional) zmq copy flag.
          track: (optional) zmq track flag.
        """

        md = dict(
            msg=msg,
            dtype=str(A.dtype),
            shape=A.shape,
        )
        self.send_json(md, flags | zmq.SNDMORE)
        return self.send(A, flags, copy=copy, track=track) 
開發者ID:jeffbass,項目名稱:imagezmq,代碼行數:24,代碼來源:imagezmq.py

示例5: send_jpg

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def send_jpg(self,
                 msg='NoName',
                 jpg_buffer=b'00',
                 flags=0,
                 copy=True,
                 track=False):
        """Send a jpg buffer with a text message.

        Sends a jpg bytestring of an OpenCV image.
        Also sends text msg, often the image name.

        Arguments:
          msg: image name or text message.
          jpg_buffer: jpg buffer of compressed image to be sent.
          flags: (optional) zmq flags.
          copy: (optional) zmq copy flag.
          track: (optional) zmq track flag.
        """

        md = dict(msg=msg, )
        self.send_json(md, flags | zmq.SNDMORE)
        return self.send(jpg_buffer, flags, copy=copy, track=track) 
開發者ID:jeffbass,項目名稱:imagezmq,代碼行數:24,代碼來源:imagezmq.py

示例6: send_multipart

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def send_multipart(self, msg_parts, flags=0, copy=True, track=False):
        """send a sequence of buffers as a multipart message
        
        The zmq.SNDMORE flag is added to all msg parts before the last.

        Parameters
        ----------
        msg_parts : iterable
            A sequence of objects to send as a multipart message. Each element
            can be any sendable object (Frame, bytes, buffer-providers)
        flags : int, optional
            SNDMORE is handled automatically for frames before the last.
        copy : bool, optional
            Should the frame(s) be sent in a copying or non-copying manner.
        track : bool, optional
            Should the frame(s) be tracked for notification that ZMQ has
            finished with it (ignored if copy=True).
    
        Returns
        -------
        None : if copy or not track
        MessageTracker : if track and not copy
            a MessageTracker object, whose `pending` property will
            be True until the last send is completed.
        """
        for msg in msg_parts[:-1]:
            self.send(msg, SNDMORE|flags, copy=copy, track=track)
        # Send the last part without the extra SNDMORE flag.
        return self.send(msg_parts[-1], flags, copy=copy, track=track) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:31,代碼來源:socket.py

示例7: submit_task

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def submit_task(self, job, indices=None):
        """Submit a task to any of a subset of our targets."""
        if indices:
            loads = [self.loads[i] for i in indices]
        else:
            loads = self.loads
        idx = self.scheme(loads)
        if indices:
            idx = indices[idx]
        target = self.targets[idx]
        # print (target, map(str, msg[:3]))
        # send job to the engine
        self.engine_stream.send(target, flags=zmq.SNDMORE, copy=False)
        self.engine_stream.send_multipart(job.raw_msg, copy=False)
        # update load
        self.add_job(idx)
        self.pending[target][job.msg_id] = job
        # notify Hub
        content = dict(msg_id=job.msg_id, engine_id=target.decode('ascii'))
        self.session.send(self.mon_stream, 'task_destination', content=content,
                        ident=[b'tracktask',self.ident])


    #-----------------------------------------------------------------------
    # Result Handling
    #----------------------------------------------------------------------- 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:28,代碼來源:scheduler.py

示例8: send_array

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def send_array(socket, A, flags=0, copy=False, track=False, block=True):
    """send a numpy array with metadata"""
    md = dict(
        dtype=str(A.dtype),
        shape=A.shape,
    )
    if block:
        socket.send_json(md, flags | zmq.SNDMORE)
        return socket.send(A, flags, copy=copy, track=track)
    else:
        try:
            socket.send_json(md, flags | zmq.SNDMORE | zmq.NOBLOCK)
            return socket.send(A, flags| zmq.NOBLOCK, copy=copy, track=track)
        except zmq.Again:
            return False 
開發者ID:naripok,項目名稱:cryptotrader,代碼行數:17,代碼來源:utils.py

示例9: send_supvisors_status

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def send_supvisors_status(self, status):
        """ This method sends a serialized form of the supvisors status
        through the socket. """
        self.logger.trace('send SupvisorsStatus {}'.format(status))
        self.socket.send_string(EventHeaders.SUPVISORS, zmq.SNDMORE)
        self.socket.send_json(status.serial()) 
開發者ID:julien6387,項目名稱:supvisors,代碼行數:8,代碼來源:supvisorszmq.py

示例10: send_address_status

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def send_address_status(self, status):
        """ This method sends a serialized form of the address status
        through the socket. """
        self.logger.trace('send RemoteStatus {}'.format(status))
        self.socket.send_string(EventHeaders.ADDRESS, zmq.SNDMORE)
        self.socket.send_json(status.serial()) 
開發者ID:julien6387,項目名稱:supvisors,代碼行數:8,代碼來源:supvisorszmq.py

示例11: send_application_status

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def send_application_status(self, status):
        """ This method sends a serialized form of the application status
        through the socket. """
        self.logger.trace('send ApplicationStatus {}'.format(status))
        self.socket.send_string(EventHeaders.APPLICATION, zmq.SNDMORE)
        self.socket.send_json(status.serial()) 
開發者ID:julien6387,項目名稱:supvisors,代碼行數:8,代碼來源:supvisorszmq.py

示例12: send_process_event

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def send_process_event(self, address, event):
        """ This method sends a process event through the socket. """
        # build the event before it is sent
        evt = event.copy()
        evt['address'] = address
        self.logger.trace('send Process Event {}'.format(evt))
        self.socket.send_string(EventHeaders.PROCESS_EVENT, zmq.SNDMORE)
        self.socket.send_json(evt) 
開發者ID:julien6387,項目名稱:supvisors,代碼行數:10,代碼來源:supvisorszmq.py

示例13: send_process_status

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def send_process_status(self, status):
        """ This method sends a serialized form of the process status
        through the socket. """
        self.logger.trace('send Process Status {}'.format(status))
        self.socket.send_string(EventHeaders.PROCESS_STATUS, zmq.SNDMORE)
        self.socket.send_json(status.serial()) 
開發者ID:julien6387,項目名稱:supvisors,代碼行數:8,代碼來源:supvisorszmq.py

示例14: send_arrays

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def send_arrays(socket, arrays, stop=False):
    """Send NumPy arrays using the buffer interface and some metadata.

    Parameters
    ----------
    socket : :class:`zmq.Socket`
        The socket to send data over.
    arrays : list
        A list of :class:`numpy.ndarray` to transfer.
    stop : bool, optional
        Instead of sending a series of NumPy arrays, send a JSON object
        with a single `stop` key. The :func:`recv_arrays` will raise
        ``StopIteration`` when it receives this.

    Notes
    -----
    The protocol is very simple: A single JSON object describing the array
    format (using the same specification as ``.npy`` files) is sent first.
    Subsequently the arrays are sent as bytestreams (through NumPy's
    support of the buffering protocol).

    """
    if arrays:
        # The buffer protocol only works on contiguous arrays
        arrays = [numpy.ascontiguousarray(array) for array in arrays]
    if stop:
        headers = {'stop': True}
        socket.send_json(headers)
    else:
        headers = [header_data_from_array_1_0(array) for array in arrays]
        socket.send_json(headers, zmq.SNDMORE)
        for array in arrays[:-1]:
            socket.send(array, zmq.SNDMORE)
        socket.send(arrays[-1]) 
開發者ID:rizar,項目名稱:attention-lvcsr,代碼行數:36,代碼來源:server.py

示例15: train_set_producer

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import SNDMORE [as 別名]
def train_set_producer(socket, train_archive, patch_archive, wnid_map):
    """Load/send images from the training set TAR file or patch images.

    Parameters
    ----------
    socket : :class:`zmq.Socket`
        PUSH socket on which to send loaded images.
    train_archive :  str or file-like object
        Filename or file handle for the TAR archive of training images.
    patch_archive :  str or file-like object
        Filename or file handle for the TAR archive of patch images.
    wnid_map : dict
        A dictionary that maps WordNet IDs to 0-based class indices.
        Used to decode the filenames of the inner TAR files.

    """
    patch_images = extract_patch_images(patch_archive, 'train')
    num_patched = 0
    with tar_open(train_archive) as tar:
        for inner_tar_info in tar:
            with tar_open(tar.extractfile(inner_tar_info.name)) as inner:
                wnid = inner_tar_info.name.split('.')[0]
                class_index = wnid_map[wnid]
                filenames = sorted(info.name for info in inner
                                   if info.isfile())
                images_gen = (load_from_tar_or_patch(inner, filename,
                                                     patch_images)
                              for filename in filenames)
                pathless_filenames = (os.path.split(fn)[-1]
                                      for fn in filenames)
                stream = equizip(pathless_filenames, images_gen)
                for image_fn, (image_data, patched) in stream:
                    if patched:
                        num_patched += 1
                    socket.send_pyobj((image_fn, class_index), zmq.SNDMORE)
                    socket.send(image_data)
    if num_patched != len(patch_images):
        raise ValueError('not all patch images were used') 
開發者ID:rizar,項目名稱:attention-lvcsr,代碼行數:40,代碼來源:ilsvrc2010.py


注:本文中的zmq.SNDMORE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。