Мне нужно одновременно запустить асинхронные функции x_scraper и y_scraper. Вот код:
async def x_get(session, t: str):
url = f'...={t}'
async with session.get(url, ssl=False) as resp:
resp_json = await resp.json(content_type=None)
async def x_scraper():
item = ['fff', 'ddd']
async with aiohttp.ClientSession() as session:
tasks = []
for t in item:
task = asyncio.create_task(x_get(session, t))
tasks.append(task)
await asyncio.gather(*tasks)
async def y_scraper():
item = ['hhh', 'ttt']
async with aiohttp.ClientSession() as session:
tasks = []
for t in item:
task = asyncio.create_task(x_get(session, t))
tasks.append(task)
await asyncio.gather(*tasks)
Я попробовал так, но функции выполняются поочередно:
from multiprocessing import Process
p1 = Process(target=asyncio.run(x_scraper()))
p1.start()
p2 = Process(target=asyncio.run(y_scraper()))
p2.start()