当前位置: 首页>>代码示例>>Python>>正文


Python IOLoop.initialized方法代码示例

本文整理汇总了Python中tornado.ioloop.IOLoop.initialized方法的典型用法代码示例。如果您正苦于以下问题:Python IOLoop.initialized方法的具体用法?Python IOLoop.initialized怎么用?Python IOLoop.initialized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.ioloop.IOLoop的用法示例。


在下文中一共展示了IOLoop.initialized方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fork_slaves

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
def fork_slaves(slave_cnt):
    from tornado.process import _pipe_cloexec, PipeIOStream
    
    is_child, lst = False, []
    for i in range(slave_cnt):
        #r, w = os.pipe()
        r, w = _pipe_cloexec()
        
        # fork можно делать только до создания ioloop'а
        # (вообще говоря любого), см. tornado.process.fork_processes()
        assert not IOLoop.initialized()
        
        pid = os.fork()
        is_child = pid == 0
        
        fd       = r if is_child else w
        to_close = w if is_child else r
        os.close(to_close)
    
        if is_child:
            res = True, (i, PipeIOStream(fd))
            # :KLUDGE: а без лишних движений как?
            for w_fd in lst:
                os.close(w_fd)
            break
        else:
            lst.append(fd)
        
    if not is_child:
        res = False, [PipeIOStream(fd) for fd in lst]
    return res
开发者ID:BradburyLab,项目名称:show_tv,代码行数:33,代码来源:mp_server.py

示例2: post_teardown

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
 def post_teardown(self):
     if (not IOLoop.initialized() or self.io_loop is not IOLoop.instance()):
         # Try to clean up any file descriptors left open in the ioloop.
         # This avoids leaks, especially when tests are run repeatedly
         # in the same process with autoreload (because curl does not
         # set FD_CLOEXEC on its file descriptors)
         self.io_loop.close(all_fds=True)
开发者ID:FSX,项目名称:akane,代码行数:9,代码来源:minitest.py

示例3: run

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
def run():
    app = Application(pages, **config)
    port = random.randrange(options.min_port, options.max_port)
    app.listen(port, address='0.0.0.0')
    signal.signal(signal.SIGCHLD, handle_sigchld)
    args = ['ab']
    args.extend(['-n', str(options.n)])
    concurrency_level = min(options.c, options.n)
    args.extend(['-c', str(concurrency_level)])
    if options.post_file is not None:
        args.extend(['-p', options.post_file])
        args.extend(['-T', 'application/json'])
    if options.email is not None:
        args.extend(['-H', 'Email:{}'.format(options.email)])
    if options.token is not None:
        args.extend(['-H', 'Token:{}'.format(options.token)])
    if options.keepalive:
        args.append('-k')
    if options.quiet:
        # just stops the progress messages printed to stderr
        args.append('-q')
    args.append('http://127.0.0.1:{}{}'.format(port, options.path))
    subprocess.Popen(args)
    IOLoop.instance().start()
    IOLoop.instance().close()
    del IOLoop._instance
    assert not IOLoop.initialized()
开发者ID:juniorsilver,项目名称:dokomoforms,代码行数:29,代码来源:benchmark_tornado.py

示例4: tearDown

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
 def tearDown(self):
     self.http_server.stop()
     self.io_loop.run_sync(self.http_server.close_all_connections)
     if (not IOLoop.initialized() or
             self.http_client.io_loop is not IOLoop.instance()):
         self.http_client.close()
     super(AsyncHTTPTestCase, self).tearDown()
开发者ID:BingQiangChen,项目名称:tornado,代码行数:9,代码来源:testing.py

示例5: close

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
    def close(self):
        """CLose http_server, io_loop by sequence, to ensure the environment
        is cleaned up and invoking `setup` successfully within next test
         function

        It is suggested to be called in `TestCase.tearDown`
        """
        self.http_server.stop()
        if (not IOLoop.initialized() or
                self.http_client.io_loop is not IOLoop.instance()):
            self.http_client.close()

        if (not IOLoop.initialized() or
                self.io_loop is not IOLoop.instance()):
            # Try to clean up any file descriptors left open in the ioloop.
            # This avoids leaks, especially when tests are run repeatedly
            # in the same process with autoreload (because curl does not
            # set FD_CLOEXEC on its file descriptors)
            self.io_loop.close(all_fds=True)
开发者ID:whtsky,项目名称:Waterspout,代码行数:21,代码来源:testing.py

示例6: close_io_loop

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
    def close_io_loop(self):
        if not IOLoop.initialized() or self.io_loop is not IOLoop.instance():
            # Try to clean up any file descriptors left open in the ioloop.
            # This avoids leaks, especially when tests are run repeatedly
            # in the same process with autoreload (because curl does not
            # set FD_CLOEXEC on its file descriptors)
            # self.io_loop.close(all_fds=True)

            # Closing all fds leads to errors. I think the client is somehow expecting it's
            # fd to still be open??
            self.io_loop.close()
开发者ID:neilkumar,项目名称:BlueOx,代码行数:13,代码来源:tornado_test.py

示例7: wrapper

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
    def wrapper(*args, **kwargs):
        cofunc = coroutine(func)
        io_loop = IOLoop.current()

        try:
            result = io_loop.run_sync(functools.partial(cofunc, *args, **kwargs))
            return result

        finally:
            io_loop.clear_current()
            if not IOLoop.initialized() or io_loop is not IOLoop.instance():
                io_loop.close(all_fds=True)
开发者ID:openpermissions,项目名称:koi,代码行数:14,代码来源:test_helpers.py

示例8: tearDown

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
 def tearDown(self):
     # Clean up Subprocess, so it can be used again with a new ioloop.
     Subprocess.uninitialize()
     self.loop.clear_current()
     if (not IOLoop.initialized() or
             self.loop is not IOLoop.instance()):
         # Try to clean up any file descriptors left open in the ioloop.
         # This avoids leaks, especially when tests are run repeatedly
         # in the same process with autoreload (because curl does not
         # set FD_CLOEXEC on its file descriptors)
         self.loop.close(all_fds=True)
     super(TornadoAPITest, self).tearDown()
开发者ID:davebshow,项目名称:gremlinclient,代码行数:14,代码来源:test_tornado_PEP492.py

示例9: tearDown

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
 def tearDown(self):
     self.io_loop.clear_current()
     if not IOLoop.initialized() or self.io_loop is not IOLoop.instance():
         # Try to clean up any file descriptors left open in the ioloop.
         # This avoids leaks, especially when tests are run repeatedly
         # in the same process with autoreload (because curl does not
         # set FD_CLOEXEC on its file descriptors)
         self.io_loop.close(all_fds=True)
     super(AsyncTestCase, self).tearDown()
     # In case an exception escaped or the StackContext caught an exception
     # when there wasn't a wait() to re-raise it, do so here.
     # This is our last chance to raise an exception in a way that the
     # unittest machinery understands.
     self.__rethrow()
开发者ID:GodZZila,项目名称:SickRage,代码行数:16,代码来源:testing.py

示例10: _publish_msg

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
 def _publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
     """Helper for sending a comm message on IOPub"""
     if threading.current_thread().name != 'MainThread' and IOLoop.initialized():
         # make sure we never send on a zmq socket outside the main IOLoop thread
         IOLoop.instance().add_callback(lambda : self._publish_msg(msg_type, data, metadata, buffers, **keys))
         return
     data = {} if data is None else data
     metadata = {} if metadata is None else metadata
     content = json_clean(dict(data=data, comm_id=self.comm_id, **keys))
     self.kernel.session.send(self.kernel.iopub_socket, msg_type,
         content,
         metadata=json_clean(metadata),
         parent=self.kernel._parent_header,
         ident=self.topic,
         buffers=buffers,
     )
开发者ID:angelapper,项目名称:ipykernel,代码行数:18,代码来源:comm.py

示例11: test_multi_process

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
 def test_multi_process(self):
     self.assertFalse(IOLoop.initialized())
     port = get_unused_port()
     def get_url(path):
         return "http://127.0.0.1:%d%s" % (port, path)
     sockets = bind_sockets(port, "127.0.0.1")
     # ensure that none of these processes live too long
     signal.alarm(5)  # master process
     try:
         id = fork_processes(3, max_restarts=3)
     except SystemExit, e:
         # if we exit cleanly from fork_processes, all the child processes
         # finished with status 0
         self.assertEqual(e.code, 0)
         self.assertTrue(task_id() is None)
         for sock in sockets: sock.close()
         signal.alarm(0)
         return
开发者ID:CoolCold,项目名称:tornado,代码行数:20,代码来源:process_test.py

示例12: run

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
def run():
    app = Application([("/", RootHandler)])
    port = random.randrange(options.min_port, options.max_port)
    app.listen(port, address='127.0.0.1')
    signal.signal(signal.SIGCHLD, handle_sigchld)
    args = ["ab"]
    args.extend(["-n", str(options.n)])
    args.extend(["-c", str(options.c)])
    if options.keepalive:
        args.append("-k")
    if options.quiet:
        # just stops the progress messages printed to stderr
        args.append("-q")
    args.append("http://127.0.0.1:%d/" % port)
    subprocess.Popen(args)
    IOLoop.instance().start()
    IOLoop.instance().close(all_fds=True)
    del IOLoop._instance
    assert not IOLoop.initialized()
开发者ID:ayanamist,项目名称:tornado-pyuv,代码行数:21,代码来源:benchmark.py

示例13: tearDown

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
 def tearDown(self):
     if (not IOLoop.initialized() or self.io_loop is not IOLoop.instance()):
         self.io_loop.close(all_fds=True)
     super(AsyncTestCase, self).tearDown()
开发者ID:URXtech,项目名称:tornado-es,代码行数:6,代码来源:test_tornadoes.py

示例14: install_asyncio

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
def install_asyncio():
    from tornado.ioloop import IOLoop
    from tornado.platform.asyncio import AsyncIOMainLoop
    '''Ensure that asyncio's io-loop is installed to tornado.'''
    if not IOLoop.initialized():
        AsyncIOMainLoop().install()
开发者ID:miyakogi,项目名称:wdom,代码行数:8,代码来源:misc.py

示例15: test_multi_process

# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import initialized [as 别名]
    def test_multi_process(self):
        self.assertFalse(IOLoop.initialized())
        port = get_unused_port()
        def get_url(path):
            return "http://127.0.0.1:%d%s" % (port, path)
        sockets = bind_sockets(port, "127.0.0.1")
        # ensure that none of these processes live too long
        signal.alarm(5)  # master process
        id = fork_processes(3, max_restarts=3)
        if id is None:
            # back in the master process; everything worked!
            self.assertTrue(task_id() is None)
            for sock in sockets: sock.close()
            signal.alarm(0)
            return
        signal.alarm(5)  # child process
        try:
            if id in (0, 1):
                signal.alarm(5)
                self.assertEqual(id, task_id())
                server = HTTPServer(self.get_app())
                server.add_sockets(sockets)
                IOLoop.instance().start()
            elif id == 2:
                signal.alarm(5)
                self.assertEqual(id, task_id())
                for sock in sockets: sock.close()
                client = HTTPClient()

                def fetch(url, fail_ok=False):
                    try:
                        return client.fetch(get_url(url))
                    except HTTPError, e:
                        if not (fail_ok and e.code == 599):
                            raise

                # Make two processes exit abnormally
                fetch("/?exit=2", fail_ok=True)
                fetch("/?exit=3", fail_ok=True)

                # They've been restarted, so a new fetch will work
                int(fetch("/").body)

                # Now the same with signals
                # Disabled because on the mac a process dying with a signal
                # can trigger an "Application exited abnormally; send error
                # report to Apple?" prompt.
                #fetch("/?signal=%d" % signal.SIGTERM, fail_ok=True)
                #fetch("/?signal=%d" % signal.SIGABRT, fail_ok=True)
                #int(fetch("/").body)

                # Now kill them normally so they won't be restarted
                fetch("/?exit=0", fail_ok=True)
                # One process left; watch it's pid change
                pid = int(fetch("/").body)
                fetch("/?exit=4", fail_ok=True)
                pid2 = int(fetch("/").body)
                self.assertNotEqual(pid, pid2)

                # Kill the last one so we shut down cleanly
                fetch("/?exit=0", fail_ok=True)

                os._exit(0)
        except Exception:
            logging.error("exception in child process %d", id, exc_info=True)
            raise
开发者ID:BillyWu,项目名称:tornado,代码行数:68,代码来源:process_test.py


注:本文中的tornado.ioloop.IOLoop.initialized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。