MCPcopy Create free account
hub / github.com/0x676e67/wreq-python / async_session_get_test

Function async_session_get_test

benchmark/bench.py:77–100  ·  view source on GitHub ↗
(session_class, url, requests_number)

Source from the content-addressed store, hash-verified

75
76
77async def async_session_get_test(session_class, url, requests_number):
78 async def aget(s, url):
79 if session_class.__module__ == "aiohttp.client":
80 async with s.get(url) as resp:
81 return await resp.read()
82 if session_class.__name__ == "Client":
83 resp = await s.get(url)
84 return await resp.bytes()
85 else:
86 resp = await s.get(url)
87 return resp.text
88
89 try:
90 async with session_class() as s:
91 tasks = [aget(s, url) for _ in range(requests_number)]
92 await asyncio.gather(*tasks)
93 except TypeError:
94 s = session_class()
95 tasks = [aget(s, url) for _ in range(requests_number)]
96 await asyncio.gather(*tasks)
97 if hasattr(s, "aclose"):
98 await s.aclose()
99 elif hasattr(s, "close"):
100 s.close()
101
102
103async def async_non_session_get_test(session_class, url, requests_number):

Callers 1

run_async_testsFunction · 0.85

Calls 2

agetFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected