How to use the tornado.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 ska-sa / katcp-python / katcp / core.py View on Github external
Example
    -------

    ::

    @tornado.gen.coroutine
    def multi_op(timeout):
        maybe_timeout = future_timeout_manager(timeout)
        result1 = yield maybe_timeout(op1())
        result2 = yield maybe_timeout(op2())
        # If the cumulative time of op1 and op2 exceeds timeout,
        # :class:`tornado.gen.TimeoutError` is raised

    """
    ioloop = ioloop or tornado.ioloop.IOLoop.current()
    t0 = ioloop.time()

    def _remaining():
        return timeout - (ioloop.time() - t0) if timeout else None

    def maybe_timeout(f):
        """Applies timeout if timeout is not None"""
        if not timeout:
            return f
        else:
            remaining = _remaining()
            deadline = ioloop.time() + remaining
            return with_timeout(deadline, f, ioloop)

    maybe_timeout.remaining = _remaining
github taiwan-online-judge / taiwan-online-judge / src / py / backend_server.py View on Github external
def start_backend_worker(ws_port):
    global backend_worker

    http_serv = tornado.httpserver.HTTPServer(tornado.web.Application([
        ('/conn',WebSocketConnHandler)
    ]))
    http_serv.listen(ws_port)

    backend_worker = BackendWorker(('10.8.0.10',5730),ws_port)
    backend_worker.start()

    tornado.ioloop.IOLoop.instance().start()
github lecher23 / tvscanner / src / main.py View on Github external
def start_update_job(self):
        tornado.ioloop.IOLoop.current().spawn_callback(self.update_async)
github coldnight / pual_bot / plugins / _fetchtitle.py View on Github external
url = ' <- '.join(reversed(fetcher.url_visited))
      logger.info('done: [%d] %s <- %s' % (fetcher.status_code, title, url))
      self.n -= 1
      if not self.n:
        tornado.ioloop.IOLoop.instance().stop()

    def add(self, url):
      TitleFetcher(url, self, url_finders=url_finders)
      self.n += 1

  from myutils import enable_pretty_logging
  enable_pretty_logging()
  f = BatchFetcher()
  for u in urls:
    f.add(u)
  tornado.ioloop.IOLoop.instance().start()
github lavalamp- / MoltenLava / LavaContentDiscovery.py View on Github external
% (r_dict['url'],)
            )
            #TODO find out how to better handle 599s
            # might want to test the endpoints before firing off the Tornado ioloop
        elif r_dict['code'] != 404:
            self.__handle_success(r_dict)
        else:
            logger.debug(
                "URL at %s returned a 404."
                % (r_dict['url'])
            )
        self.__do_maintenance()
        if not self._ready_for_stop:
            self.__send_next()
        elif self._num_outstanding == 0:
            tornado.ioloop.IOLoop.instance().stop()
github Knio / carhack / carhack / sensors / gps_nmea / __init__.py View on Github external
import time
import logging

import tornado.ioloop

import carhack.sensors

log = logging.getLogger('nmea')
ioloop = tornado.ioloop.IOLoop.instance()

import serial
import threading

class SerialNMEA(carhack.sensors.Sensor):
  def __init__(self, filename='\\\\.\\COM6'):
    self.filename = filename
    self.timeout = 5.
    self.thread = threading.Thread(target=self.run)
    self.thread.daemon = True
    self.running = True
    self.thread.start()

  def close(self):
    self.running = False
github cuthbertLab / music21 / music21 / ext / nbconvert / postprocessors / serve.py View on Github external
cdn=self.reveal_cdn,
            client=AsyncHTTPClient(),
        )
        
        # hook up tornado logging to our logger
        log.app_log = self.log

        http_server = httpserver.HTTPServer(app)
        http_server.listen(self.port, address=self.ip)
        url = "http://%s:%i/%s" % (self.ip, self.port, filename)
        print("Serving your slides at %s" % url)
        print("Use Control-C to stop this server")
        if self.open_in_browser:
            webbrowser.open(url, new=2)
        try:
            ioloop.IOLoop.instance().start()
        except KeyboardInterrupt:
            print("\nInterrupted")
github psobot / foreverfm / forever / relay.py View on Github external
len(StreamHandler.listeners)),
        config.restart_timeout * 1000
    ).start()
    tornado.ioloop.PeriodicCallback(update, 5000).start()

    application = tornado.web.Application([
        (r"/all.mp3", StreamHandler),
        (r"/", InfoHandler)
    ])

    frame_sender = threading.Thread(target=StreamHandler.stream_frames)
    frame_sender.daemon = True
    frame_sender.start()

    application.listen(config.http_port)
    tornado.ioloop.IOLoop.instance().start()
github splunk / splunk-sdk-python / examples / analytics / bottle.py View on Github external
def run(self, handler): # pragma: no cover
        import tornado.wsgi
        import tornado.httpserver
        import tornado.ioloop
        container = tornado.wsgi.WSGIContainer(handler)
        server = tornado.httpserver.HTTPServer(container)
        server.listen(port=self.port)
        tornado.ioloop.IOLoop.instance().start()
github gregbayer / logcatcher / tornado / catch_logs.py View on Github external
class HeartbeatHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Web server is up...")


application = tornado.web.Application([
        (r"/put_logs", LogCatcherHandler),
        (r"/index.html", HeartbeatHandler),
    ])

if __name__ == "__main__":
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(8080)
    tornado.ioloop.IOLoop.instance().start()