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


Python tulip.set_event_loop函数代码示例

本文整理汇总了Python中tulip.set_event_loop函数的典型用法代码示例。如果您正苦于以下问题:Python set_event_loop函数的具体用法?Python set_event_loop怎么用?Python set_event_loop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: run

    def run(loop, fut):
        thread_loop = tulip.new_event_loop()
        tulip.set_event_loop(thread_loop)

        server = thread_loop.run_until_complete(
            thread_loop.create_server(
                lambda: TestHttpServer(keep_alive=0.5),
                host, port, ssl=sslcontext))

        waiter = tulip.Future(loop=thread_loop)
        loop.call_soon_threadsafe(
            fut.set_result, (thread_loop, waiter,
                             server.sockets[0].getsockname()))

        try:
            thread_loop.run_until_complete(waiter)
        finally:
            # call pending connection_made if present
            run_briefly(thread_loop)

            # close opened trnsports
            for tr in transports:
                tr.close()

            run_briefly(thread_loop)  # call close callbacks

            server.close()
            thread_loop.stop()
            thread_loop.close()
            gc.collect()
开发者ID:oohlaf,项目名称:asynchttp,代码行数:30,代码来源:test_utils.py

示例2: start

    def start(self):
        assert not self._started
        self._started = True

        up_read, up_write = os.pipe()
        down_read, down_write = os.pipe()
        args, sock = self.args, self.sock

        pid = os.fork()
        if pid:
            # parent
            os.close(up_read)
            os.close(down_write)
            tulip.async(self.connect(pid, up_write, down_read))
        else:
            # child
            os.close(up_write)
            os.close(down_read)

            # cleanup after fork
            tulip.set_event_loop(None)

            # setup process
            process = ChildProcess(up_read, down_write, args, sock)
            process.start()
开发者ID:oohlaf,项目名称:asynchttp,代码行数:25,代码来源:wssrv.py

示例3: setUp

    def setUp(self):
        self.loop = tulip.new_event_loop()
        tulip.set_event_loop(self.loop)

        self.transport = unittest.mock.Mock()
        self.stream = tulip.StreamBuffer()
        self.response = HttpResponse('get', 'http://python.org')
开发者ID:sah,项目名称:tulip,代码行数:7,代码来源:http_session_test.py

示例4: run

    def run(loop, fut):
        thread_loop = tulip.new_event_loop()
        tulip.set_event_loop(thread_loop)

        socks = thread_loop.run_until_complete(
            thread_loop.start_serving(
                lambda: TestHttpServer(keep_alive=0.5),
                host, port, ssl=sslcontext))

        waiter = tulip.Future()
        loop.call_soon_threadsafe(
            fut.set_result, (thread_loop, waiter, socks[0].getsockname()))

        thread_loop.run_until_complete(waiter)

        # close opened trnsports
        for tr in transports:
            tr.close()

        run_once(thread_loop)  # call close callbacks

        for s in socks:
            thread_loop.stop_serving(s)

        thread_loop.stop()
        thread_loop.close()
        gc.collect()
开发者ID:tehmaze,项目名称:telnetlib3,代码行数:27,代码来源:test_utils.py

示例5: __init__

    def __init__(self):
        self.loop = tulip.get_event_loop()
        args = ARGS.parse_args()
        if ':' in args.host:
            args.host, port = args.host.split(':', 1)
            args.port = int(port)

        if args.iocp:
            from tulip import windows_events
            sys.argv.remove('--iocp')
            logging.info('using iocp')
            el = windows_events.ProactorEventLoop()
            tulip.set_event_loop(el)

        if args.ssl:
            here = os.path.join(os.path.dirname(__file__), 'tests')

            if args.certfile:
                certfile = args.certfile or os.path.join(here, 'sample.crt')
                keyfile = args.keyfile or os.path.join(here, 'sample.key')
            else:
                certfile = os.path.join(here, 'sample.crt')
                keyfile = os.path.join(here, 'sample.key')

            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
            sslcontext.load_cert_chain(certfile, keyfile)
        else:
            sslcontext = None
        self.ssl = sslcontext

        self.args = args
        self.workers = []
开发者ID:avelino,项目名称:nacho,代码行数:32,代码来源:multithreading.py

示例6: _io_event_loop_thread

 def _io_event_loop_thread(self):
     """Worker thread for running the I/O event loop"""
     io_event_loop = tulip.get_event_loop_policy().new_event_loop()
     tulip.set_event_loop(io_event_loop)
     assert isinstance(io_event_loop, AbstractEventLoop)
     self._io_event_loop = io_event_loop
     self._event_loop_started.release()
     self._io_event_loop.run_forever()
开发者ID:emillynge,项目名称:asyncio-tkinter,代码行数:8,代码来源:guievents.py

示例7: init_process

    def init_process(self):
        # create new event_loop after fork
        tulip.get_event_loop().close()

        self.ev_loop = tulip.new_event_loop()
        tulip.set_event_loop(self.ev_loop)

        super().init_process()
开发者ID:zakdances,项目名称:gtulip,代码行数:8,代码来源:worker.py

示例8: run_server

 def run_server(cls, host, port):
     handler = StaticFilesHandler(get_internal_wsgi_application())
     # Save the event loop for the thread in a class variable
     # so we can unblock it when the tests are finished.
     cls.server_thread_loop = tulip.new_event_loop()
     tulip.set_event_loop(cls.server_thread_loop)
     cls.server_stop = tulip.Future()
     run(host, port, handler, cls.server_thread_loop, cls.server_stop)
     cls.server_thread_loop.close()
开发者ID:azizur77,项目名称:django-c10k-demo,代码行数:9,代码来源:test.py

示例9: setUp

 def setUp(self):
     super().setUp()
     self.loop = tulip.new_event_loop()
     tulip.set_event_loop(self.loop)
     self.protocol = WebSocketCommonProtocol()
     self.transport = unittest.mock.Mock()
     self.transport.close = unittest.mock.Mock(
             side_effect=lambda: self.protocol.connection_lost(None))
     self.protocol.connection_made(self.transport)
开发者ID:fdion,项目名称:webfive-pyjs,代码行数:9,代码来源:test_protocol.py

示例10: run

def run(addr, port, wsgi_handler, ipv6=False, threading=False):
    """
    Alternate version of django.core.servers.basehttp.run running on Tulip.
    """
    assert not ipv6, "IPv6 isn't supported"
    assert threading, "threading is irrelevant"
    httpd = WSGIServer(addr, port, WSGIRequestHandler)
    httpd.set_app(wsgi_handler)
    # The auto-reloader runs in the main thread and starts the server in
    # another thread. Since the event loop in thread-local we must create one.
    loop = tulip.get_event_loop()
    if loop is None:
        loop = tulip.new_event_loop()
        tulip.set_event_loop(loop)
    loop.start_serving(httpd, addr, port)
    loop.run_forever()
开发者ID:bigmlcom,项目名称:django-c10k-demo,代码行数:16,代码来源:tulip.py

示例11: setUp

    def setUp(self):
        self.loop = tulip.new_event_loop()
        tulip.set_event_loop(None)

        self.wsgi = unittest.mock.Mock()
        self.stream = unittest.mock.Mock()
        self.transport = unittest.mock.Mock()
        self.transport.get_extra_info.return_value = '127.0.0.1'

        self.headers = []
        self.message = protocol.RawRequestMessage(
            'GET', '/path', (1, 0), self.headers, True, 'deflate')
        self.payload = tulip.DataBuffer()
        self.payload.feed_data(b'data')
        self.payload.feed_data(b'data')
        self.payload.feed_eof()
开发者ID:concordusapps,项目名称:tulip,代码行数:16,代码来源:http_wsgi_test.py

示例12: test_use_global_loop

    def test_use_global_loop(self):
        with test_utils.run_test_server(self.loop, router=Functional) as httpd:
            try:
                tulip.set_event_loop(self.loop)
                r = self.loop.run_until_complete(
                    client.request('get', httpd.url('method', 'get')))
            finally:
                tulip.set_event_loop(None)
            content1 = self.loop.run_until_complete(r.read())
            content2 = self.loop.run_until_complete(r.read())
            content = content1.decode()

            self.assertEqual(r.status, 200)
            self.assertIn('"method": "GET"', content)
            self.assertEqual(content1, content2)
            r.close()
开发者ID:concordusapps,项目名称:tulip,代码行数:16,代码来源:http_client_functional_test.py

示例13: run

def run(addr, port, wsgi_handler, **options):
    """
    Alternate version of django.core.servers.basehttp.run running on Tulip.
    """
    loop = tulip.get_event_loop()
    if loop is None:
        # The auto-reloader runs in the main thread and starts the server
        # in another thread. Create an event loop for that thread.
        loop = tulip.new_event_loop()
        tulip.set_event_loop(loop)
    # The code that reads environ['wsgi.input'] is deep inside Django and hard
    # to make asynchronous. Pre-loading the payload is the simplest option.
    protocol_factory = lambda: tulip.http.WSGIServerHttpProtocol(
            wsgi_handler, readpayload=True)
    loop.start_serving(protocol_factory, addr, port)
    loop.run_forever()
开发者ID:gelliravi,项目名称:django-c10k-demo,代码行数:16,代码来源:runserver.py

示例14: run

def run(addr, port, wsgi_handler, loop=None, stop=None, **options):
    """
    Alternate version of django.core.servers.basehttp.run running on Tulip.
    """
    if loop is None:
        loop = tulip.new_event_loop()
        tulip.set_event_loop(loop)
    # The code that reads environ['wsgi.input'] is deep inside Django and hard
    # to make asynchronous. Pre-loading the payload is the simplest option.
    protocol_factory = lambda: tulip.http.WSGIServerHttpProtocol(
            wsgi_handler, readpayload=True)
    sockets = loop.start_serving(protocol_factory, addr, port)
    if stop is None:
        loop.run_forever()
    else:
        loop.run_until_complete(stop)
        for socket in sockets:
            loop.stop_serving(socket)
开发者ID:azizur77,项目名称:django-c10k-demo,代码行数:18,代码来源:runserver.py

示例15: start

    def start(self):
        # start server
        self.loop = loop = tulip.new_event_loop()
        tulip.set_event_loop(loop)

        def stop():
            self.loop.stop()
            os._exit(0)
        loop.add_signal_handler(signal.SIGINT, stop)

        f = loop.start_serving(
            self.protocol_factory, sock=self.sock, ssl=self.ssl)
        x = loop.run_until_complete(f)[0]
        print('Starting srv worker process {} on {}'.format(
            os.getpid(), x.getsockname()))

        # heartbeat
        self.heartbeat()

        tulip.get_event_loop().run_forever()
        os._exit(0)
开发者ID:avelino,项目名称:nacho,代码行数:21,代码来源:multithreading.py


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