How to use the zmq.PUSH function in zmq

To help you get started, we’ve selected a few zmq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github powerapi-ng / powerapi / smartwatts / actor / actor_pull.py View on Github external
def connect(self):
        """
        initialize the push/pull connection with the actor
        """
        # define the push_socket on the client side
        self.push_socket = self.context.socket(zmq.PUSH)
        # connect to the pull socket on the server_side
        self.push_socket.connect(self.pull_socket_address)
        self.log('connected to ' + self.pull_socket_address)
github cachedout / eventdriventalk / telemetry / load_beacon.py View on Github external
#/usr/bin/env python2.7
import zmq
import os
import socket
import time
import core.framer

# Create a context
ctx = zmq.Context()

# Our tag
tag = '/client/load/silver'
while True:
    # Frame it up
    event = framer.pack(tag, {'cur_load': os.getloadavg()})
    socket = ctx.socket(zmq.PUSH)
    socket.connect('tcp://localhost:2001')
    socket.send(event)
    socket.close()
    time.sleep(1)
github lukasheinrich / ipython-chat / ipythonchat.py View on Github external
def handle_input(sender):
        context = zmq.Context()
        push_socket = context.socket(zmq.PUSH)
        push_socket.connect(socket_address)

        push_socket.send_json({'plain_message':{'nickname':my_nickname,'message':sender.value}})
        sender.value = ''
github leapcode / bitmask_client / src / leap / bitmask / logs / safezmqhandler.py View on Github external
def _get_new_socket(self):
        """
        Return a new socket using the `uri` and `multi` parameters given in the
        constructor.

        :rtype: zmq.Socket
        """
        socket = None

        if self._multi:
            socket = self.context.socket(zmq.PUSH)
            if self._uri is not None:
                socket.connect(self._uri)
        else:
            socket = self.context.socket(zmq.PUB)
            if self._uri is not None:
                socket.bind(self._uri)

        return socket
github VOLTTRON / volttron / applications / pnnl / AFDDAgent / afdd / Archive / agent_mt.py View on Github external
def run():
                sock = messaging.Socket(zmq.PUSH)
                sock.connect(publish_address)
                with contextlib.closing(sock):
                    algo(self, sock)
            self.thread = threading.Thread(target=run)
github leapcode / leap_pycommon / src / leap / common / events / client.py View on Github external
def _zmq_connect_push(self):
        """
        Initialize the client's PUSH connection.

        :return: A ZMQ connection stream.
        :rtype: ZMQStream
        """
        return self._zmq_connect(zmq.PUSH, self._emit_addr)
github CompuCell3D / CompuCell3D / CompuCell3D / optimization / OptimizerWorkerProcessZMQ.py View on Github external
def send_abort_message(self,push_address, worker_tag):
        """
        Used in case simulation throws an exception . IN this case we are sending abort message to
        optimization runner (Optimizer)
        :return: None
        """
        context = zmq.Context()


        consumer_sender = context.socket(zmq.PUSH)
        consumer_sender.connect(push_address)

        result = {'return_value_tag': worker_tag, 'return_value': -1,'abort':True}


        consumer_sender.send_json(result)
github hanxiao / bert-as-service / server / bert_serving / server / __init__.py View on Github external
    @zmqd.socket(zmq.PUSH)
    @multi_socket(zmq.PULL, num_socket='num_concurrent_socket')
    def _run(self, sink_embed, sink_token, *receivers):
        # Windows does not support logger in MP environment, thus get a new logger
        # inside the process for better compatibility
        logger = set_logger(colored('WORKER-%d' % self.worker_id, 'yellow'), self.verbose)

        logger.info('use device %s, load graph from %s' %
                    ('cpu' if self.device_id < 0 else ('gpu: %d' % self.device_id), self.graph_path))

        tf = import_tf(self.device_id, self.verbose, use_fp16=self.use_fp16)
        estimator = self.get_estimator(tf)

        for sock, addr in zip(receivers, self.worker_address):
            sock.connect(addr)

        sink_embed.connect(self.sink_address)
github pkumusic / E-DRL / tensorpack / dataflow / remote.py View on Github external
def serve_data(ds, addr):
    ctx = zmq.Context()
    socket = ctx.socket(zmq.PUSH)
    socket.set_hwm(10)
    socket.bind(addr)
    ds = RepeatedData(ds, -1)
    try:
        ds.reset_state()
        logger.info("Serving data at {}".format(addr))
        # TODO print statistics here
        while True:
            for dp in ds.get_data():
                socket.send(dumps(dp), copy=False)
    finally:
        socket.setsockopt(zmq.LINGER, 0)
        socket.close()
        if not ctx.closed:
            ctx.destroy(0)
github qq456cvb / doudizhu-C / TensorPack / A3C / simulator.py View on Github external
def run(self):
        player = self._build_player()
        context = zmq.Context()
        c2s_socket = context.socket(zmq.PUSH)
        c2s_socket.setsockopt(zmq.IDENTITY, self.identity)
        c2s_socket.set_hwm(10)
        c2s_socket.connect(self.c2s)

        s2c_socket = context.socket(zmq.DEALER)
        s2c_socket.setsockopt(zmq.IDENTITY, self.identity)
        s2c_socket.connect(self.s2c)

        player.reset()
        # init_cards = np.arange(52)
        # init_cards = np.append(init_cards[::4], init_cards[1::4])
        # player.prepare_manual(init_cards)
        player.prepare()
        r, is_over = 0, False
        lstm_state = np.zeros([1024 * 2])
        while True: