aiomultiprocess创建一个池,但是不起作用

时间:2019-04-30 08:55:05

标签: python-3.6

import asyncio
import aiohttp
import time, json
from aiomultiprocess import Pool

start = time.time()
url = 'http://member-service.test.cn/member/login'
headers = {"Content-Type": "application/json;charset=UTF-8"}


async def get(phone):
    session = aiohttp.ClientSession()
    response = await session.post(url=url, data=json.dumps(
        {"identityType": 1, "password": "111111", "platformSource": "Mall", "remember": True,
         "terminalType": "PC", 'identity': phone}), headers=headers)
    result = await response.text()
    session.close()
    print(result)
    return result


async def request():
    phones = ['186%08d' % x for x in range(0, 10)]
    async with Pool() as pool:
        result = await pool.map(get, phones) # can't work
        return result

coroutine = request()
task = asyncio.ensure_future(coroutine)
loop = asyncio.get_event_loop()
loop.run_until_complete(task)

end = time.time()
print('Cost time:', end - start)

我尝试使用aiomultiprocess创建一个池。

async with Pool() as pool:
        result = await pool.map(get, phones) 

但实际上不能调用get函数

0 个答案:

没有答案