run_session(): minor code cleanup
This commit is contained in:
parent
c4cad63a4e
commit
15414aa378
1 changed files with 4 additions and 5 deletions
|
|
@ -950,18 +950,17 @@ def write_mode(orig_func):
|
|||
return f
|
||||
|
||||
def run_session(callback,backend=None):
|
||||
backend = backend or opt.rpc_backend
|
||||
import asyncio
|
||||
|
||||
async def do():
|
||||
if backend == 'aiohttp':
|
||||
if (backend or opt.rpc_backend) == 'aiohttp':
|
||||
import aiohttp
|
||||
async with aiohttp.ClientSession(
|
||||
headers = { 'Content-Type': 'application/json' },
|
||||
connector = aiohttp.TCPConnector(limit_per_host=g.aiohttp_rpc_queue_len),
|
||||
) as g.session:
|
||||
ret = await callback
|
||||
return ret
|
||||
return await callback
|
||||
else:
|
||||
return await callback
|
||||
|
||||
import asyncio
|
||||
return asyncio.run(do())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue