import config
import asyncio
import aiohttp
import uuid
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
async def request(session, **kwargs):
logger.info(f"proc_id : {str(proc_id)}")
async with session.post(
config.URL,
params=kwargs
) as response:
ret = await response.json()
return ret
async def post_multipletimes(**kwargs):
run_request = False
id_list = list()
id_loop = 0
INTERVAL = 10
success = True
loop_total = 0
while True:
async with aiohttp.ClientSession() as session:
id_loop += 1
success = False if loop_total > 50 else True
id_list.append(id_loop)
if id_loop % INTERVAL == 0:
run_request = True
else:
if success is True:
continue
if len(id_list) > 0:
run_request = True
else:
break
if run_request:
tasks = list()
for id_loop in id_list
tasks.append(
request(
session, dict(id_loop=id_loop)
)
)
res = await asyncio.gather(*tasks)
for r_loop in res:
result_list.extend(r_loop)
run_request = False
id_list = list()
loop_total += 1
if success == False:
break
return ret