當前位置: 首頁>>代碼示例>>Python>>正文


Python asyncio.AnyThreadEventLoopPolicy方法代碼示例

本文整理匯總了Python中tornado.platform.asyncio.AnyThreadEventLoopPolicy方法的典型用法代碼示例。如果您正苦於以下問題:Python asyncio.AnyThreadEventLoopPolicy方法的具體用法?Python asyncio.AnyThreadEventLoopPolicy怎麽用?Python asyncio.AnyThreadEventLoopPolicy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.platform.asyncio的用法示例。


在下文中一共展示了asyncio.AnyThreadEventLoopPolicy方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_policy_test

# 需要導入模塊: from tornado.platform import asyncio [as 別名]
# 或者: from tornado.platform.asyncio import AnyThreadEventLoopPolicy [as 別名]
def run_policy_test(self, accessor, expected_type):
        # With the default policy, non-main threads don't get an event
        # loop.
        self.assertRaises((RuntimeError, AssertionError),
                          self.executor.submit(accessor).result)
        # Set the policy and we can get a loop.
        asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
        self.assertIsInstance(
            self.executor.submit(accessor).result(),
            expected_type)
        # Clean up to silence leak warnings. Always use asyncio since
        # IOLoop doesn't (currently) close the underlying loop.
        self.executor.submit(lambda: asyncio.get_event_loop().close()).result() 
開發者ID:tp4a,項目名稱:teleport,代碼行數:15,代碼來源:asyncio_test.py

示例2: _run

# 需要導入模塊: from tornado.platform import asyncio [as 別名]
# 或者: from tornado.platform.asyncio import AnyThreadEventLoopPolicy [as 別名]
def _run(self):

        started = Event()

        def start():
            log.info('Starting Jupyter server in separate thread')
            asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
            notebook_dir = base_system_path(self._data.base, subdir=NOTEBOOKS)
            options = ['--notebook-dir', notebook_dir]
            if self._bind is not None: options += ['--ip', self._bind]
            if self._port is not None: options += ['--port', str(self._port)]
            if global_dev(): options += ['--debug', '--log-level=DEBUG']
            if not geteuid(): options += ['--allow-root', '--no-browser']
            # https://github.com/jupyter/notebook/issues/2254
            options += ['--NotebookApp.token=""']
            log.debug(f'Jupyter options: {options}')
            JupyterServer.launch_instance(options, started=started)

        t = Thread(target=start)
        t.daemon = True
        t.start()
        started.wait()  # set in JupyterServer.start() which is as late as we can get in startup
        log.debug('Separate thread started')

        while not hasattr(JupyterServer._instance, 'connection_url') or not JupyterServer._instance.connection_url:
            log.debug('Waiting for connection URL')
            sleep(1)
        old_url = JupyterServer._instance.connection_url
        new_url = uriunsplit(urisplit(old_url)._replace(authority=f'{self._proxy_bind}:{self._proxy_port}'))
        log.debug(f'Rewrote {old_url} -> {new_url}')
        self._data.sys.set_constant(SystemConstant.JUPYTER_URL, new_url, force=True)

        log.info('Jupyter server started')
        while True:
            sleep(1) 
開發者ID:andrewcooke,項目名稱:choochoo,代碼行數:37,代碼來源:server.py

示例3: _init_event_loop_policy

# 需要導入模塊: from tornado.platform import asyncio [as 別名]
# 或者: from tornado.platform.asyncio import AnyThreadEventLoopPolicy [as 別名]
def _init_event_loop_policy(self):
        asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy()) 
開發者ID:Karmenzind,項目名稱:fp-server,代碼行數:4,代碼來源:context.py

示例4: on_message

# 需要導入模塊: from tornado.platform import asyncio [as 別名]
# 或者: from tornado.platform.asyncio import AnyThreadEventLoopPolicy [as 別名]
def on_message(self, message):
        asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
        parsed_message = json.loads(message)

        invalid_params_resp = await self.get_invalid_params_resp(parsed_message)
        if invalid_params_resp:
            self.write_message(invalid_params_resp.as_dict())
            self.close()

        notebook_path = os.path.join(SAGEMAKER_FOLDER, parsed_message["notebook_path"].lstrip("/"))

        containerization_status_logger = ContainerizationStatusLoggerBuilder.build(
            notebook_path)
        log_time_fields = {"containerization_start": time.time(),
            "notebook_modification_time": os.path.getmtime(notebook_path)}

        initial_status = ContainerizationStatusLogEntry.of_image_creation(
            notebook_path, error_msg=None, progress=0)
        self.log_and_write_status(containerization_status_logger, initial_status)

        last_status = initial_status
        try:
            containerized_kernel_name = parsed_message["kernel_name"]
            annotations = self.get_manifest_annotations(
                parsed_message["variables"],
                parsed_message["container_name"],
                parsed_message["container_description"])
            repository_name = parsed_message["repository_name"]
            repository_uri = await self.get_repository_uri(repository_name)

            if not repository_uri:
                error_msg = "Destination repository {} does not exist.".format(
                    repository_name)
                log_entry = ContainerizationStatusLogEntry.of_image_creation(
                    notebook_path, error_msg=error_msg, progress=0)
                self.log_and_write_status(containerization_status_logger, log_entry)
                self.clear()
                self.close(HTTPStatus.NOT_FOUND)
                return

            statuses = self.containerize_and_upload(repository_name, repository_uri,
                containerized_kernel_name, notebook_path, log_time_fields, annotations)
            async for status in statuses:
                last_status = status
                self.log_and_write_status(containerization_status_logger, status)
                if status.error_msg:
                    self.close(HTTPStatus.OK)
                    return
        except:
            last_status.error_msg = CONTAINERIZATION_UNHANDLED_ERROR_MSG
            last_status.error_trace = traceback.format_exc()
            self.log_and_write_status(containerization_status_logger, last_status)
            logger.exception("Caught unhandled exception while creating or uploading image.")
            raise
        finally:
            self.close(HTTPStatus.OK) 
開發者ID:awslabs,項目名稱:aws-iot-analytics-notebook-containers,代碼行數:58,代碼來源:export_to_ecr.py


注:本文中的tornado.platform.asyncio.AnyThreadEventLoopPolicy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。