Пример #1
0
 def _default_loop(self):
     loop = IOLoop.current()
     if not isinstance(loop, ZMQIOLoop):
         raise TypeError("Current tornado IOLoop is %r, not a ZMQIOLoop."
                         "  Run `zmq.eventloop.ioloop.install() first." %
                         loop)
     return loop
Пример #2
0
 def _default_loop(self):
     loop = IOLoop.current()
     if not isinstance(loop, ZMQIOLoop):
         raise TypeError(
             "Current tornado IOLoop is %r, not a ZMQIOLoop."
             "  Run `zmq.eventloop.ioloop.install() first." % loop)
     return loop
Пример #3
0
 def __init__(self, context, socket_type, io_loop=None):
     super(Socket, self).__init__(context, socket_type)
     self.io_loop = io_loop or IOLoop.current()
     self._recv_futures = []
     self._send_futures = []
     self._state = 0
     self._shadow_sock = _zmq.Socket.shadow(self.underlying)
     self._init_io_state()
Пример #4
0
 def __init__(self, context, socket_type, io_loop=None):
     super(Socket, self).__init__(context, socket_type)
     self.io_loop = io_loop or IOLoop.current()
     self._recv_futures = []
     self._send_futures = []
     self._state = 0
     self._shadow_sock = _zmq.Socket.shadow(self.underlying)
     self._init_io_state()
Пример #5
0
def main1():
    """Server routine"""
    args = sys.argv[1:]
    if len(args) != 0:
        sys.exit(__doc__)
    loop = IOLoop.current()
    #loop.run_sync(lambda: run1('a string'))
    loop.run_sync(partial(run1, 'a string'))
Пример #6
0
def main1():
    """Server routine"""
    args = sys.argv[1:]
    if len(args) != 0:
        sys.exit(__doc__)
    loop = IOLoop.current()
    #loop.run_sync(lambda: run1('a string'))
    loop.run_sync(partial(run1, 'a string'))
Пример #7
0
    def poll(self, timeout=-1):
        """Return a Future for a poll event"""
        future = Future()
        if timeout == 0:
            try:
                result = super(Poller, self).poll(0)
            except Exception as e:
                future.set_exception(e)
            else:
                future.set_result(result)
            return future

        loop = IOLoop.current()

        # register Future to be called as soon as any event is available on any socket
        # only support polling on zmq sockets, for now
        watcher = Future()
        for socket, mask in self.sockets:
            if mask & _zmq.POLLIN:
                socket._add_recv_event('poll', future=watcher)
            if mask & _zmq.POLLOUT:
                socket._add_send_event('poll', future=watcher)

        def on_poll_ready(f):
            if future.done():
                return
            if watcher.exception():
                future.set_exception(watcher.exception())
            else:
                try:
                    result = super(Poller, self).poll(0)
                except Exception as e:
                    future.set_exception(e)
                else:
                    future.set_result(result)

        watcher.add_done_callback(on_poll_ready)

        if timeout > 0:
            # schedule cancel to fire on poll timeout, if any
            def trigger_timeout():
                if not watcher.done():
                    watcher.set_result(None)

            timeout_handle = loop.call_later(1e-3 * timeout, trigger_timeout)

            def cancel_timeout(f):
                loop.remove_timeout(timeout_handle)

            future.add_done_callback(cancel_timeout)

        def cancel_watcher(f):
            if not watcher.done():
                watcher.cancel()

        future.add_done_callback(cancel_watcher)

        return future
Пример #8
0
    def poll(self, timeout=-1):
        """Return a Future for a poll event"""
        future = Future()
        if timeout == 0:
            try:
                result = super(Poller, self).poll(0)
            except Exception as e:
                future.set_exception(e)
            else:
                future.set_result(result)
            return future

        loop = IOLoop.current()

        # register Future to be called as soon as any event is available on any socket
        # only support polling on zmq sockets, for now
        watcher = Future()
        for socket, mask in self.sockets:
            if mask & _zmq.POLLIN:
                socket._add_recv_event("poll", future=watcher)
            if mask & _zmq.POLLOUT:
                socket._add_send_event("poll", future=watcher)

        def on_poll_ready(f):
            if future.done():
                return
            if watcher.exception():
                future.set_exception(watcher.exception())
            else:
                try:
                    result = super(Poller, self).poll(0)
                except Exception as e:
                    future.set_exception(e)
                else:
                    future.set_result(result)

        watcher.add_done_callback(on_poll_ready)

        if timeout > 0:
            # schedule cancel to fire on poll timeout, if any
            def trigger_timeout():
                if not watcher.done():
                    watcher.set_result(None)

            timeout_handle = loop.call_later(1e-3 * timeout, trigger_timeout)

            def cancel_timeout(f):
                loop.remove_timeout(timeout_handle)

            future.add_done_callback(cancel_timeout)

        def cancel_watcher(f):
            if not watcher.done():
                watcher.cancel()

        future.add_done_callback(cancel_watcher)

        return future
Пример #9
0
def main2():
    """Server routine"""
    args = sys.argv[1:]
    if len(args) != 0:
        sys.exit(__doc__)
    loop = IOLoop.current()
    loop.add_callback(partial(run2, 'another string', loop))
    loop.start()
    print('(main2) after loop.start')
Пример #10
0
def main2():
    """Server routine"""
    args = sys.argv[1:]
    if len(args) != 0:
        sys.exit(__doc__)
    loop = IOLoop.current()
    loop.add_callback(partial(run2, 'another string', loop))
    loop.start()
    print('(main2) after loop.start')
Пример #11
0
def main():
    args = sys.argv[1:]
    if len(args) != 0:
        sys.exit(__doc__)
    try:
        loop = IOLoop.current()
        loop.run_sync(partial(run, loop))
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #12
0
def main():
    args = sys.argv[1:]
    if len(args) != 0:
        sys.exit(__doc__)
    try:
        loop = IOLoop.current()
        loop.run_sync(partial(run, loop, ))
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #13
0
def main():
    args = sys.argv[1:]
    if len(args) != 1:
        sys.exit(__doc__)
    ident = args[0]
    try:
        loop = IOLoop.current()
        loop.run_sync(lambda: run(ident))
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #14
0
def main():
    """
    bw main function
    """
    # bw daemon options
    opts = options.options()
    # Riak key-value storage
    db = riak.RiakClient(host=opts.riak_host, pb_port=8087)
    # System uuid
    system_uuid = uuid.uuid4()
    # System spawned
    logging.info("bw {0} spawned".format(system_uuid))
    # debug riak settings
    logging.info("Riak server: {0}:{1}".format(opts.riak_host, opts.riak_port))
    # application web daemon
    application = web.Application(
        [
            (r"/status/?", StatusHandler),
            (r"/games/page/(?P<page_num>\d+)/?", games.Handler),
            (r"/games/(?P<game_uuid>.+)/?", games.Handler),
            (r"/games/?", games.Handler),
        ],
        db=db,
        debug=opts.debug,
        domain=opts.domain,
        page_size=opts.page_size,
    )
    # Listen daemon on port
    application.listen(opts.port)
    logging.info("Listen on http://{0}:{1}".format(opts.host, opts.port))

    # Setting up the ZeroMQ integration
    IOLoop.current().spawn_callback(partial(
        run,
        opts.host,
        opts.port,
    ))
    # missing collector as well?
    # D: D: D:
    # where is your zstreams stuff?

    # Start the eventloop
    ioloop.IOLoop.instance().start()
Пример #15
0
def main():
    args = sys.argv[1:]
    if len(args) != 0:
        sys.exit(__doc__)
    try:
        loop = IOLoop.current()
        loop.add_callback(lambda: run(loop))
        loop.start()
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #16
0
def main():
    args = sys.argv[1:]
    if len(args) > 1:
        sys.exit(__doc__)
    zip_filter = sys.argv[1] if len(sys.argv) > 1 else "10001"
    try:
        loop = IOLoop.current()
        loop.run_sync(partial(run, loop, zip_filter))
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #17
0
def main():
    args = sys.argv[1:]
    if len(args) != 0:
        sys.exit(__doc__)
    try:
        loop = IOLoop.current()
        loop.add_callback(partial(run, loop))
        loop.start()
    except KeyboardInterrupt:
        print("\nFinished (interrupted)")
Пример #18
0
def main():
    args = sys.argv[1:]
    if len(args) != 1:
        sys.exit(__doc__)
    ident = args[0]
    try:
        loop = IOLoop.current()
        loop.run_sync(lambda: run(ident))
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #19
0
def main():
    args = sys.argv[1:]
    if len(args) > 1:
        sys.exit(__doc__)
    zip_filter = sys.argv[1] if len(sys.argv) > 1 else "10001"
    try:
        loop = IOLoop.current()
        loop.run_sync(partial(run, loop, zip_filter))
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #20
0
def main():
    args = sys.argv[1:]
    if len(args) < 1:
        sys.exit(__doc__)
    zipcodes = args
    print('Running async/await version.')
    try:
        loop = IOLoop.current()
        loop.run_sync(partial(run, loop, zipcodes))
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #21
0
def main():
    args = sys.argv[1:]
    if len(args) != 2:
        sys.exit(__doc__)
    try:
        ident = args[0]
        num_workers = int(args[1])
        loop = IOLoop.current()
        loop.run_sync(partial(run, loop, ident, num_workers, ))
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #22
0
def main():
    args = sys.argv[1:]
    if len(args) != 0:
        sys.exit(__doc__)
    try:
        loop = IOLoop.current()
        loop.add_callback(lambda: run())
        loop.start()
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
        sys.exit(0)
Пример #23
0
def main():
    args = sys.argv[1:]
    if len(args) < 1:
        sys.exit(__doc__)
    zipcodes = args
    print('Running async/await version.')
    try:
        loop = IOLoop.current()
        loop.run_sync(partial(run, loop, zipcodes))
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #24
0
def main():
    """main function"""
    print('(main) starting')
    args = sys.argv[1:]
    if len(args) != 0:
        sys.exit(__doc__)
    try:
        loop = IOLoop.current()
        loop.run_sync(partial(run, loop))
        print('(main) after starting run()')
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #25
0
def main():
    args = sys.argv[1:]
    if len(args) == 1:
        num_requests = int(args[0])
    elif len(args) == 0:
        num_requests = 10
    else:
        sys.exit(__doc__)
    try:
        loop = IOLoop.current()
        loop.run_sync(partial(run, loop, num_requests, ))
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #26
0
def main():
    args = sys.argv[1:]
    if len(args) != 2:
        sys.exit(__doc__)
    try:
        ident = args[0]
        num_workers = int(args[1])
        loop = IOLoop.current()
        loop.run_sync(partial(
            run,
            loop,
            ident,
            num_workers,
        ))
    except KeyboardInterrupt:
        print('\nFinished (interrupted)')
Пример #27
0
 def _loop_default(self):
     from zmq.eventloop.ioloop import IOLoop
     return IOLoop.current()
Пример #28
0
def start_ioloop():
	loop = IOLoop.current()
	try:
		loop.start()
	except KeyboardInterrupt:
		sys.exit(1)
Пример #29
0
 def _loop_default(self):
     from zmq.eventloop.ioloop import IOLoop
     return IOLoop.current()
Пример #30
0
 def start_in_ioloop(self):
     """Start the timer."""
     ioloop = IOLoop.current()
     self._timeout = ioloop.add_timeout(
         ioloop.time() + self.callback_time / 1000.0, self.callback)
Пример #31
0
 def start_in_ioloop(self):
     """Start the timer."""
     ioloop = IOLoop.current()
     self._timeout = ioloop.add_timeout(
         ioloop.time() + self.callback_time / 1000.0, self.callback)
Пример #32
0
logging.basicConfig(level=logging.DEBUG)

class MainHandler(tornado.web.RequestHandler):
    def initialize(self, client):
        self._client = client

    def get(self):
        loop.add_callback(foo)

    async def get(self):
        ec, height = await self._client.last_height()
        if ec:
            self.write("Error reading block height: %s" % ec)
            return
        self.write("Last block height is %s" % height)

def make_app(context):
    client = context.Client("tcp://gateway.unsystem.net:9091")
    return tornado.web.Application([
        (r"/", MainHandler, dict(client=client)),
    ])

if __name__ == "__main__":
    context = libbitcoin.TornadoContext()
    app = make_app(context)
    app.listen(8888)
    loop = IOLoop.current()
    context.start(loop)
    loop.start()

Пример #33
0
 def __init__(self, *args, **kwargs):
     io_loop = kwargs.pop('io_loop', None)
     super(Context, self).__init__(*args, **kwargs)
     self.io_loop = io_loop or IOLoop.current()
Пример #34
0
 def _default_loop(self):
     return IOLoop.current()
Пример #35
0
 def stop(self):
     """Stop the timer."""
     if self._timeout is not None:
         ioloop = IOLoop.current()
         ioloop.remove_timeout(self._timeout)
         self._timeout = None
Пример #36
0
 def __init__(self, *args, **kwargs):
     io_loop = kwargs.pop('io_loop', None)
     super(Context, self).__init__(*args, **kwargs)
     self.io_loop = io_loop or IOLoop.current()
Пример #37
0
class MainHandler(tornado.web.RequestHandler):
    def initialize(self, client):
        self._client = client

    def get(self):
        loop.add_callback(foo)

    async def get(self):
        ec, height = await self._client.last_height()
        if ec:
            self.write("Error reading block height: %s" % ec)
            return
        self.write("Last block height is %s" % height)


def make_app(context):
    client = context.Client("tcp://gateway.unsystem.net:9091")
    return tornado.web.Application([
        (r"/", MainHandler, dict(client=client)),
    ])


if __name__ == "__main__":
    context = libbitcoin.TornadoContext()
    app = make_app(context)
    app.listen(8888)
    loop = IOLoop.current()
    context.start(loop)
    loop.start()
Пример #38
0
 def _loop_default(self):
     return IOLoop.current()
Пример #39
0
 def stop(self):
     """Stop the timer."""
     if self._timeout is not None:
         ioloop = IOLoop.current()
         ioloop.remove_timeout(self._timeout)
         self._timeout = None
Пример #40
0
 def _loop_default(self):
     return IOLoop.current()
Пример #41
0
 def _default_loop(self):
     return IOLoop.current()
Пример #42
0
def curr_loop():  # pragma: no cover
    return IOLoop.current()