How to use the tornado.ioloop.IOLoop 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 RobotWebTools / rosbridge_suite / rosbridge_tools / src / tornado / autoreload.py View on Github external
def wait():
    """Wait for a watched file to change, then restart the process.

    Intended to be used at the end of scripts like unit test runners,
    to run the tests again after any source file changes (but see also
    the command-line interface in `main`)
    """
    io_loop = ioloop.IOLoop()
    start(io_loop)
    io_loop.start()
github madisonmay / BlackWidow / blackwidow / viz / server.py View on Github external
def serve(data, port=None):
    """
    Render graph visualization
    """
    DataHandler.json_data = data
    application.listen(port or config.PORT)
    print("Navigate to http://localhost:%d/ to view the package graph" % config.PORT)
    tornado.ioloop.IOLoop.current().start()
github enthought / jigna / examples / ex3_simple_view_web.py View on Github external
def main():
    # Start the tornado ioloop application
    ioloop = IOLoop.instance()

    # Instantiate the domain model
    fred = Person(name='Fred', age=42)

    # Create a web app serving the view with the domain model added to its
    # context.
    app = WebApp(template=template, context={'person': fred})
    app.listen(8000)

    # Start serving the web app on port 8000.
    #
    # Point your web browser to http://localhost:8000/ to connect to this jigna
    # web app. Any operation performed on the client directly update the
    # model attributes on the server.
    print('Serving on port 8000...')
    ioloop.start()
github hhru / frontik / frontik / jobs.py View on Github external
def work(func, cb, exception_cb):
    try:
        result = func()
        tornado.ioloop.IOLoop.instance().add_callback(functools.partial(cb, result))
    except Exception, e:
        tornado.ioloop.IOLoop.instance().add_callback(functools.partial(exception_cb, e)) 
github pymedusa / Medusa / lib / tornado / platform / twisted.py View on Github external
def connectionLost(self, reason):
        if not self.lost:
            self.handler(self.fileobj, tornado.ioloop.IOLoop.ERROR)
            self.lost = True
github MagicStack / vmbench / servers / torecho.py View on Github external
stream.set_nodelay(True)
        self._stream.read_until_close(None, self._handle_read)

    def _handle_read(self, data):
        self._stream.write(data)


class EchoServer(TCPServer):
    def handle_stream(self, stream, address):
        StreamHandler(stream)

if __name__ == '__main__':
    server = EchoServer()
    server.bind(25000)
    server.start(1)
    IOLoop.instance().start()
    IOLoop.instance().close()
github hadim / jupyter-archive / jupyter_archive / handlers.py View on Github external
def get(self, archive_path, include_body=False):

        # /extract-archive/ requests must originate from the same site
        self.check_xsrf_cookie()
        cm = self.contents_manager

        if cm.is_hidden(archive_path) and not cm.allow_hidden:
            self.log.info("Refusing to serve hidden file, via 404 Error")
            raise web.HTTPError(404)

        archive_path = os.path.join(cm.root_dir, url2path(archive_path))
        archive_path = pathlib.Path(archive_path)

        yield ioloop.IOLoop.current().run_in_executor(None, self.extract_archive, archive_path)

        self.finish()
github kennell / curldrop / runcurldrop.py View on Github external
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from os.path import isfile, isdir
from os import makedirs
from curldrop import app, init_db

http_server = HTTPServer(WSGIContainer(app))
http_server.listen(app.config['PORT'])

if not isfile(app.config['DATABASE']):
		init_db()

if not isdir(app.config['UPLOADDIR']):
		makedirs(app.config['UPLOADDIR'])

IOLoop.instance().start()
github zulip / zulip / zerver / tornado / websocket_client.py View on Github external
def connect(self) -> Generator[str, WebSocketClientConnection, None]:
        try:
            request = HTTPRequest(url=self._get_websocket_url(), validate_cert=self.validate_ssl)
            request.headers.add('Cookie', self.cookie_str)
            self.ws = yield websocket_connect(request)
            yield self.ws.read_message()
            yield self._websocket_auth(self.events_data, self.cookie_dict)
            self.run_on_start(self, **self.run_kwargs)
        except Exception as e:
            logging.exception(str(e))
            IOLoop.instance().stop()
        IOLoop.instance().stop()
github thisismedium / python-xmpp-server / xmpp / aio.py View on Github external
def loop():
    if not hasattr(IOLoop, '_instance'):
        poll = _KQueue() if hasattr(select, 'kqueue') else None
        IOLoop._instance = IOLoop(poll)
    return IOLoop._instance