Python tornado.ioloop 模块,add_callback() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用tornado.ioloop.add_callback()

项目:funcserver    作者:deep-compute    | 项目源码 | 文件源码
def on_close(self):
        '''
        Called when client closes this connection. Cleanup
        is done here.
        '''

        if self.id in self.funcserver.websocks:
            self.funcserver.websocks[self.id] = None
            ioloop = tornado.ioloop.IOLoop.instance()
            ioloop.add_callback(lambda: self.funcserver.websocks.pop(self.id, None))

        psession = self.funcserver.pysessions.get(self.pysession_id, None)
        if psession:
            psession['socks'].remove(self.id)
            if not psession['socks']:
                del self.funcserver.pysessions[self.pysession_id]
项目:jumpscale_portal    作者:jumpscale7    | 项目源码 | 文件源码
def main(j, args, params, tags, tasklet):
    params.merge(args)

    import tornado.ioloop
    def stop_portal():
        ioloop = tornado.ioloop.IOLoop.current()
        ioloop.add_callback(lambda x: x.sys.exit(3), tornado.ioloop)

    stop_portal()

    params.result = ('Portal is reloaded', params.doc)

    return params
项目:wsrpc    作者:sloev    | 项目源码 | 文件源码
def stop_ioloop():
    logging.info("stopping ws_rpc ioloop")
    ioloop = tornado.ioloop.IOLoop.instance()
    ioloop.add_callback(ioloop.stop)
项目:Polyglot    作者:UniversalDevicesInc    | 项目源码 | 文件源码
def unload():
    ''' stops the http server '''
    ioloop = tornado.ioloop.IOLoop.instance()
    ioloop.add_callback(lambda x: x.stop(), ioloop)
    _LOGGER.info('Unloaded HTTP element')
项目:wptagent    作者:WPO-Foundation    | 项目源码 | 文件源码
def stop(self):
        """Stop running the server"""
        logging.debug("Shutting down extension server")
        self.must_exit = True
        if self.thread is not None:
            ioloop = tornado.ioloop.IOLoop.instance()
            ioloop.add_callback(ioloop.stop)
            self.thread.join()
        self.thread = None
        logging.debug("Extension server stopped")
项目:funcserver    作者:deep-compute    | 项目源码 | 文件源码
def call(fn):
    ioloop = tornado.ioloop.IOLoop.instance()
    ioloop.add_callback(fn)
项目:Polyglot    作者:UniversalDevicesInc    | 项目源码 | 文件源码
def register(handlers=None, subdomain=None, parent_dir=None, urls=None):
    '''
    Register additional handlers to the server.

    :param handlers: List of handler classes to register.
    :param subdomain: The desired subdomain
    :param parent_dir: The directory under which all the handlers should be
                       placed
    :param urls: List of lists like [['path', Handler]].
                 Overwrites handlers input.
    '''
    # parse input
    if subdomain is None:
        subdomain = "[A-Za-z0-9.]*"
    else:
        subdomain = r'{}\.[A-Za-z0-9.]*'.format(subdomain)

    if parent_dir is None:
        parent_dir = ''
    else:
        parent_dir = '/{}'.format(parent_dir)

    # create proper URLSpec handlers and callback
    if not urls:
        def doc_url(handler):
            """ reads the url regexp from the handler's docstring. """
            docs = handler.__doc__
            pieces = docs.strip().split('\n\n')[0].split('\n')
            return ''.join([piece.strip() for piece in pieces])
        handlers = [tornado.web.URLSpec('{}{}'.format(parent_dir,
                                                      doc_url(handler)),
                                        handler)
                    for handler in handlers]
    else:
        handlers = urls

    def add_handler_callback(server, subdmn, hndls):
        """ add handler to server """
        server.add_handlers(subdmn, hndls)

    # schedule handler addition to next IOLoop iteration
    ioloop = tornado.ioloop.IOLoop.instance()
    ioloop.add_callback(add_handler_callback, SERVER, subdomain, handlers)