Esempio n. 1
0
    server = ctx.socket(zmq.PUSH)
    server.bind('tcp://*:9000')
    for i in range(5000):
        await server.send(b'Hello %d' % i)
    await server.send(b'exit')

async def pulling():
    client = ctx.socket(zmq.PULL)
    client.connect('tcp://127.0.0.1:9000')
    with open(os.devnull, 'w') as null:
        while True:
            greeting = await client.recv_multipart()
            if greeting[0] == b'exit': 
                break
            print(greeting[0], file=null)

async def main():
    t = await spawn(pushing)
    try:
        begin = time.monotonic()
        await pulling()
        end = time.monotonic()
        print('curio + pyzmq: {:.6f} sec.'.format(end - begin))
    except KeyboardInterrupt:
        pass

if __name__ == '__main__':
    zmq.run(main)


Esempio n. 2
0
    server.bind('tcp://*:9000')
    for i in range(5000):
        await server.send(b'Hello %d' % i)
    await server.send(b'exit')


async def pulling():
    client = ctx.socket(zmq.PULL)
    client.connect('tcp://127.0.0.1:9000')
    with open(os.devnull, 'w') as null:
        while True:
            greeting = await client.recv_multipart()
            if greeting[0] == b'exit':
                break
            print(greeting[0], file=null)


async def main():
    t = await spawn(pushing)
    try:
        begin = time.monotonic()
        await pulling()
        end = time.monotonic()
        print('curio + pyzmq: {:.6f} sec.'.format(end - begin))
    except KeyboardInterrupt:
        pass


if __name__ == '__main__':
    zmq.run(main)
Esempio n. 3
0
# zmq pull client example.  Requires zmq_pusher.py to be running

import curio.zmq as zmq


async def puller(address):
    ctx = zmq.Context()
    sock = ctx.socket(zmq.PULL)
    sock.connect(address)
    while True:
        msg = await sock.recv()
        if msg == b'exit':
            break
        print('Got:', msg)


if __name__ == '__main__':
    zmq.run(puller('tcp://localhost:9000'))
Esempio n. 4
0
# zmq push example. Run the zmq_puller.py program for the client

import curio.zmq as zmq

async def pusher(address):
    ctx = zmq.Context()
    sock = ctx.socket(zmq.PUSH)
    sock.bind(address)
    for n in range(100):
        await sock.send(b'Message %d' % n)
    await sock.send(b'exit')

if __name__ == '__main__':
    zmq.run(pusher('tcp://*:9000'))
Esempio n. 5
0
# zmq pull client example.  Requires zmq_pusher.py to be running

import curio.zmq as zmq


async def puller(address):
    ctx = zmq.Context()
    sock = ctx.socket(zmq.PULL)
    sock.connect(address)
    while True:
        msg = await sock.recv()
        if msg == b'exit':
            break
        print('Got:', msg)


if __name__ == '__main__':
    zmq.run(puller, 'tcp://localhost:9000')
Esempio n. 6
0
    server.bind('tcp://*:9000')
    for i in range(5000):
        await server.send(b'Hello %d' % i)
    await server.send(b'exit')


async def pulling():
    client = ctx.socket(zmq.PULL)
    client.connect('tcp://127.0.0.1:9000')
    with open(os.devnull, 'w') as null:
        while True:
            greeting = await client.recv_multipart()
            if greeting[0] == b'exit':
                break
            print(greeting[0], file=null)


async def main():
    t = await spawn(pushing())
    try:
        begin = time.monotonic()
        await pulling()
        end = time.monotonic()
        print('curio + pyzmq: {:.6f} sec.'.format(end - begin))
    except KeyboardInterrupt:
        pass


if __name__ == '__main__':
    zmq.run(main())
Esempio n. 7
0
            f'{prefix}:COUNT': germ.count_channel,
            f'{prefix}:UUID:CHIP': germ.uid_chip_channel,
            f'{prefix}:UUID:CHAN': germ.uid_chan_channel,
            f'{prefix}:UUID:TD': germ.uid_td_channel,
            f'{prefix}:UUID:PD': germ.uid_pd_channel,
            f'{prefix}:UUID:TS': germ.uid_ts_channel,
            }
    return Context('0.0.0.0', find_next_tcp_port(), pvdb), germ


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='IOC to front GeRM zmq server')
    parser.add_argument('zync_host', type=str,
                        help='ip of the Zync server')
    parser.add_argument('collector_host', type=str,
                        help='ip of the udp collector')
    args = parser.parse_args()

    zync_ip = args.zync_host
    collector_ip = args.collector_host

    fs = Registry({'dbpath': '/tmp/fs.sqlite'})
    ctx, germ = create_server(f'tcp://{zync_ip}', f'tcp://{collector_ip}', fs)

    async def runner():
        await ctx.run()

    zmq.run(runner)
Esempio n. 8
0
# zmq rpc example.

import curio.zmq as zmq


async def rpc_server(address):
    ctx = zmq.Context()
    sock = ctx.socket(zmq.REP)
    sock.bind(address)
    while True:
        func, args, kwargs = await sock.recv_pyobj()
        try:
            result = func(*args, **kwargs)
            await sock.send_pyobj(result)
        except Exception as e:
            await sock.send_pyobj(e)


if __name__ == '__main__':
    zmq.run(rpc_server, 'tcp://*:9000')
Esempio n. 9
0
# zmq rpc example.

import curio.zmq as zmq


async def rpc_server(address):
    ctx = zmq.Context()
    sock = ctx.socket(zmq.REP)
    sock.bind(address)
    while True:
        func, args, kwargs = await sock.recv_pyobj()
        try:
            result = func(*args, **kwargs)
            await sock.send_pyobj(result)
        except Exception as e:
            await sock.send_pyobj(e)


if __name__ == '__main__':
    zmq.run(rpc_server('tcp://*:9000'))
Esempio n. 10
0
# zmq push example. Run the zmq_puller.py program for the client

import curio.zmq as zmq


async def pusher(address):
    ctx = zmq.Context()
    sock = ctx.socket(zmq.PUSH)
    sock.bind(address)
    for n in range(100):
        await sock.send(b'Message %d' % n)
    await sock.send(b'exit')


if __name__ == '__main__':
    zmq.run(pusher, 'tcp://*:9000')
Esempio n. 11
0
import curio.zmq as zmq
from curio import sleep, spawn

from hello import fib


async def ticker():
    n = 0
    while True:
        await sleep(1)
        print('Tick:', n)
        n += 1


async def client(address):
    # Run a background task to make sure the message passing operations don't block
    await spawn(ticker, daemon=True)

    # Compute the first 40 fibonacci numbers
    ctx = zmq.Context()
    sock = ctx.socket(zmq.REQ)
    sock.connect(address)
    for n in range(1, 40):
        await sock.send_pyobj((fib, (n, ), {}))
        result = await sock.recv_pyobj()
        print(n, result)


if __name__ == '__main__':
    zmq.run(client, 'tcp://localhost:9000')
Esempio n. 12
0
import curio.zmq as zmq
from curio import sleep, spawn

from hello import fib


async def ticker():
    n = 0
    while True:
        await sleep(1)
        print('Tick:', n)
        n += 1


async def client(address):
    # Run a background task to make sure the message passing operations don't block
    await spawn(ticker(), daemon=True)

    # Compute the first 40 fibonacci numbers
    ctx = zmq.Context()
    sock = ctx.socket(zmq.REQ)
    sock.connect(address)
    for n in range(1, 40):
        await sock.send_pyobj((fib, (n, ), {}))
        result = await sock.recv_pyobj()
        print(n, result)


if __name__ == '__main__':
    zmq.run(client('tcp://localhost:9000'))