tornado: construct AsyncHTTPClient each time so that it uses the right ioloop

This is a better fix for #129.
This commit is contained in:
lilydjwg 2020-07-02 15:07:19 +08:00
parent 2fc1ec3355
commit cbd7e13867
2 changed files with 2 additions and 5 deletions

View file

@ -17,7 +17,6 @@ from .httpclient import DEFAULT_USER_AGENT
__all__ = ['session', 'HTTPError', 'NetworkErrors'] __all__ = ['session', 'HTTPError', 'NetworkErrors']
client = AsyncHTTPClient()
HTTP2_AVAILABLE = None if pycurl else False HTTP2_AVAILABLE = None if pycurl else False
def try_use_http2(curl): def try_use_http2(curl):
@ -66,7 +65,7 @@ class ResponseManager:
self.req = req self.req = req
async def __aenter__(self): async def __aenter__(self):
return await client.fetch(self.req) return await AsyncHTTPClient().fetch(self.req)
async def __aexit__(self, exc_type, exc, tb): async def __aexit__(self, exc_type, exc, tb):
pass pass

View file

@ -54,12 +54,10 @@ async def get_version():
return __call__ return __call__
@pytest.fixture(scope="session") @pytest.fixture(scope="module")
def event_loop(request): def event_loop(request):
"""Override pytest-asyncio's event_loop fixture, """Override pytest-asyncio's event_loop fixture,
Don't create an instance of the default event loop for each test case. Don't create an instance of the default event loop for each test case.
The scope is session because the Tornado AsyncHTTPClient singleton remains.
""" """
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
yield loop yield loop