'Proper use of pool.map
I have an asynchronous function that checks if the token is valid. I want to count how many working and non-working tokens. Also I use aiomultiprocess. The code below works, but I think I did it wrong. Can you point out my mistakes?
import aiohttp
from aiomultiprocess import Pool
async def check_valid_tokens(token, valid=0, invalid=0):
headers = {
'authorization': f'{token}',
}
async with aiohttp.ClientSession() as session:
async with session.get(url="url", headers=headers) as response:
if response.status == 200:
valid += 1
elif response.status == 401:
invalid += 1
return valid, invalid
async def check_document(file):
valid = 0
invalid = 0
async with Pool() as pool:
async for result in pool.map(check_valid_tokens, tokens):
valid += result[0]
invalid += result[1]
return valid, invalid
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
