示例#1
0
文件: zmq.py 项目: tacaswell/xpdAn
    def __init__(self,
                 address,
                 *,
                 prefix=None,
                 loop=None,
                 zmq=None,
                 zmq_asyncio=None,
                 deserializer=pickle.loads):
        if prefix and b' ' in prefix:
            raise ValueError("prefix {!r} may not contain b' '".format(prefix))
        if isinstance(prefix, str):
            prefix = [prefix]
        self._prefix = prefix
        if zmq is None:
            import zmq
        if zmq_asyncio is None:
            import zmq.asyncio as zmq_asyncio
        if isinstance(address, str):
            address = address.split(':', maxsplit=1)
        self._deserializer = deserializer
        self.address = (address[0], int(address[1]))

        if loop is None:
            loop = zmq_asyncio.ZMQEventLoop()
        self.loop = loop
        asyncio.set_event_loop(self.loop)
        self._context = zmq_asyncio.Context()
        self._socket = self._context.socket(zmq.SUB)
        url = "tcp://%s:%d" % self.address
        self._socket.connect(url)
        self._socket.setsockopt_string(zmq.SUBSCRIBE, "")
        self._task = None

        super().__init__()
示例#2
0
def cli(frontend, backend):
    loop = zmq_asyncio.ZMQEventLoop()
    asyncio.set_event_loop(loop)

    rpc_broker = broker.Broker(loop)
    rpc_broker.bind(frontend, backend)

    tasks = rpc_broker.run()
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        tasks.cancel()
        raise
    finally:
        loop.close()
示例#3
0
def cli(broker, service, task):
    logger.warn(broker)
    loop = zmq_asyncio.ZMQEventLoop()
    asyncio.set_event_loop(loop)
    service, task = tasks[task]
    rpc_client = client.RPCClient(broker, service.encode('utf-8'), loop)
    task = loop.create_task(task(rpc_client))
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        rpc_client.close()
        task.cancel()
        try:
            loop.run_until_complete(task)
        except:
            pass
        finally:
            raise
    finally:
        loop.close()
示例#4
0
    def __init__(self,
                 address,
                 *,
                 hostname=None,
                 pid=None,
                 run_engine_id=None,
                 loop=None,
                 zmq=None,
                 zmq_asyncio=None):
        if zmq is None:
            import zmq
        if zmq_asyncio is None:
            import zmq.asyncio as zmq_asyncio
        if isinstance(address, str):
            address = address.split(':', maxsplit=1)
        self.address = (address[0], int(address[1]))
        self.hostname = hostname
        self.pid = pid
        self.run_engine_id = run_engine_id

        if loop is None:
            loop = zmq_asyncio.ZMQEventLoop()
        self.loop = loop
        asyncio.set_event_loop(self.loop)
        self._context = zmq_asyncio.Context()
        self._socket = self._context.socket(zmq.SUB)
        url = "tcp://%s:%d" % self.address
        self._socket.connect(url)
        self._socket.setsockopt_string(zmq.SUBSCRIBE, "")
        self._task = None

        def is_our_message(_hostname, _pid, _RE_id):
            # Close over filters and decide if this message applies to this
            # RemoteDispatcher.
            return ((hostname is None or hostname == _hostname)
                    and (pid is None or pid == _pid) and
                    (run_engine_id is None or run_engine_id == run_engine_id))

        self._is_our_message = is_our_message

        super().__init__()
示例#5
0
}
mds = MDSRO(d)
fs = RegistryRO(d)
fs.register_handler('AD_TIFF', AreaDetectorTiffHandler)
db = Broker(mds=mds, reg=fs)
td = TemporaryDirectory()
source = conf_main_pipeline(
    db,
    td.name,
    # vis=False,
    write_to_disk=False,
    # mask_setting=None
)

# a = LiveImage('pe1_image')
loop = zmq_asyncio.ZMQEventLoop()
install_qt_kicker(loop=loop)


def put_in_queue(nd):
    if nd[0] == 'event':
        nd[1]['data']['pe1_image'] = np.asarray(nd[1]['data']['pe1_image'])
    # if nd[0] == 'event':
    #     db.fill_event(nd[1])
    # print(nd)
    # source.emit(nd)
    a(*nd)
    plt.pause(.1)


disp = RemoteDispatcher('127.0.0.1:5568', loop=loop)
示例#6
0
 def setUp(self):
     if asyncio is None:
         raise SkipTest()
     self.loop = zaio.ZMQEventLoop()
     asyncio.set_event_loop(self.loop)
     super().setUp()
 def setUp(self):
     self.loop = zaio.ZMQEventLoop()
     asyncio.set_event_loop(self.loop)
     super().setUp()