Skip to content

Commit

Permalink
fix event loop bug with aiohttp 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
wang0618 committed Nov 5, 2021
1 parent 3869738 commit 41b866f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pywebio/platform/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)
7 changes: 7 additions & 0 deletions pywebio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 41b866f

Please sign in to comment.