How to use the tornado.ioloop.IOLoop.current function in tornado

To help you get started, we’ve selected a few tornado 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 dask / distributed / distributed / bokeh / tasks / server_lifecycle.py View on Github external
def on_server_loaded(server_context):
    IOLoop.current().add_callback(task_events, **messages['task-events'])
github xxdongs / github-trending / manage.py View on Github external
app = tornado.web.Application([
    (r'/', IndexHandler),
    (r'/repo/', RepositoryHandler),
    (r'/repo', RepositoryHandler),
    (r'/repo/(.+)', RepositoryLanguageHandler),
    (r'/developer/', DeveloperHandler),
    (r'/developer', DeveloperHandler),
    (r'/developer/(.+)', DeveloperLanguageHandler),
])

if __name__ == '__main__':
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.current().start()
github tp4a / teleport / server / www / packages / packages-common / tornado / locks.py View on Github external
Block if the counter is zero and wait for a `.release`. The Future
        raises `.TimeoutError` after the deadline.
        """
        waiter = Future()
        if self._value > 0:
            self._value -= 1
            waiter.set_result(_ReleasingContextManager(self))
        else:
            self._waiters.append(waiter)
            if timeout:
                def on_timeout():
                    if not waiter.done():
                        waiter.set_exception(gen.TimeoutError())
                    self._garbage_collect()
                io_loop = ioloop.IOLoop.current()
                timeout_handle = io_loop.add_timeout(timeout, on_timeout)
                waiter.add_done_callback(
                    lambda _: io_loop.remove_timeout(timeout_handle))
        return waiter
github hhru / frontik / frontik / futures.py View on Github external
return
        res_future.set_result(processed)

    def _on_ready(wrapped_future):
        exception = wrapped_future.exception()
        if exception is not None:
            if not callable(exception_mapper):
                def default_exception_func(error):
                    raise error
                _process(default_exception_func, exception)
            else:
                _process(exception_mapper, exception)
        else:
            _process(result_mapper, future.result())

    IOLoop.current().add_future(future, callback=_on_ready)
    return res_future
github radiasoft / sirepo / sirepo / pkcli / job_agent.py View on Github external
def terminate(self):
        try:
            x = self.cmds
            self.cmds.clear()
            for c in x:
                try:
                    c.destroy()
                except Exception as e:
                    pkdlog('cmd={} error={} stack={}', c, e, pkdexc())
            return None
        finally:
            tornado.ioloop.IOLoop.current().stop()
github pymedusa / Medusa / lib / tornado / process.py View on Github external
def __init__(self, *args, **kwargs):
        self.io_loop = kwargs.pop('io_loop', None) or ioloop.IOLoop.current()
        # All FDs we create should be closed on error; those in to_close
        # should be closed in the parent process on success.
        pipe_fds = []
        to_close = []
        if kwargs.get('stdin') is Subprocess.STREAM:
            in_r, in_w = _pipe_cloexec()
            kwargs['stdin'] = in_r
            pipe_fds.extend((in_r, in_w))
            to_close.append(in_r)
            self.stdin = PipeIOStream(in_w, io_loop=self.io_loop)
        if kwargs.get('stdout') is Subprocess.STREAM:
            out_r, out_w = _pipe_cloexec()
            kwargs['stdout'] = out_w
            pipe_fds.extend((out_r, out_w))
            to_close.append(out_w)
            self.stdout = PipeIOStream(out_r, io_loop=self.io_loop)
github dragondjf / CloudSetuper / setuper web app / tornado / websocket.py View on Github external
"""Client-side websocket support.

    Takes a url and returns a Future whose result is a
    `WebSocketClientConnection`.

    ``compression_options`` is interpreted in the same way as the
    return value of `.WebSocketHandler.get_compression_options`.

    .. versionchanged:: 3.2
       Also accepts ``HTTPRequest`` objects in place of urls.

    .. versionchanged:: 4.1
       Added ``compression_options``.
    """
    if io_loop is None:
        io_loop = IOLoop.current()
    if isinstance(url, httpclient.HTTPRequest):
        assert connect_timeout is None
        request = url
        # Copy and convert the headers dict/object (see comments in
        # AsyncHTTPClient.fetch)
        request.headers = httputil.HTTPHeaders(request.headers)
    else:
        request = httpclient.HTTPRequest(url, connect_timeout=connect_timeout)
    request = httpclient._RequestProxy(
        request, httpclient.HTTPRequest._DEFAULTS)
    conn = WebSocketClientConnection(io_loop, request, compression_options)
    if callback is not None:
        io_loop.add_future(conn.connect_future, callback)
    return conn.connect_future
github codelv / enaml-native / src / enamlnative / core / loop.py View on Github external
def _default_loop(self):
        from tornado.ioloop import IOLoop
        return IOLoop.current()
github uber / mutornadomon / sample_application.py View on Github external
def stop(*args):
        print 'Good bye'
        monitor.stop()
        tornado.ioloop.IOLoop.current().stop()
github pymedusa / Medusa / lib / tornado / queues.py View on Github external
def _set_timeout(future, timeout):
    if timeout:
        def on_timeout():
            future.set_exception(gen.TimeoutError())
        io_loop = ioloop.IOLoop.current()
        timeout_handle = io_loop.add_timeout(timeout, on_timeout)
        future.add_done_callback(
            lambda _: io_loop.remove_timeout(timeout_handle))