Encourage creation of aiohttp public objects inside a coroutine #3331
Closed
Description
I would enforce it. For example, constructing CleintSession in a module global namespace is a bad smell and leads to hard-to-debug errors very often.
The plan is:
- Add
helpers.get_running_loop()function with the following implementation:
def get_running_loop(loop=None):
if loop is None:
loop = asyncio.get_event_loop()
if not loop.is_running():
warnings.warn("The object should be created from async function",
DeprecationWarning,
stacklevel=3)
- Replace
asyncio.get_event_loop()withget_running_loop()in all aiohttp objects. - Replace a deprecation warning with
RuntimeError()in aiohttp 4.0