diff --git a/pywebio/platform/aiohttp.py b/pywebio/platform/aiohttp.py index 0359a398..40d355cc 100644 --- a/pywebio/platform/aiohttp.py +++ b/pywebio/platform/aiohttp.py @@ -13,7 +13,7 @@ from .utils import make_applications, render_page, cdn_validation, deserialize_binary_event from ..session import CoroutineBasedSession, ThreadBasedSession, register_session_implement_for_target, Session from ..session.base import get_session_info_from_headers -from ..utils import get_free_port, STATIC_PATH, iscoroutinefunction, isgeneratorfunction +from ..utils import get_free_port, STATIC_PATH, iscoroutinefunction, isgeneratorfunction, func_params logger = logging.getLogger(__name__) @@ -208,4 +208,9 @@ def start_server(applications, port=0, host='', debug=False, if remote_access: start_remote_access_service(local_port=port) - web.run_app(app, host=host, port=port) + if 'loop' in func_params(web.run_app): + # after aiohttp 3.8, aiohttp.web.run_app() create new loop by default, we need to pass current loop explicitly. + # see: https://github.com/aio-libs/aiohttp/pull/5572 + web.run_app(app, host=host, port=port, loop=asyncio.get_event_loop()) + else: + web.run_app(app, host=host, port=port) diff --git a/pywebio/utils.py b/pywebio/utils.py index a5bc911f..14f7d8ac 100644 --- a/pywebio/utils.py +++ b/pywebio/utils.py @@ -378,3 +378,10 @@ def strip_space(text, n): for i in text.splitlines() ) return '\n'.join(lines) + + +def func_params(func): + """Return the parameter name list of the function + """ + signature = inspect.signature(func) + return list(signature.parameters.keys())