Python asyncio 由于某种原因卡住了
Python asyncio stuck for some reason
我试图运行其中的一个例子
page。由于某种原因它不起作用,如果你 运行 这个程序它会打印随机数量的 "hi" 然后它会卡住。我正在使用 python 3.6.0,你能帮我找出问题所在吗?
import asyncio
import aiohttp
import bs4
@asyncio.coroutine
def print_page(url):
response = yield from aiohttp.request('GET', url)
body = yield from response.text()
print(body)
@asyncio.coroutine
def get(*args, **kwargs):
response = yield from aiohttp.request('GET', *args, **kwargs)
return (yield from response.text())
def first_magnet(page):
return "hi"
@asyncio.coroutine
def print_magnet(query):
url = 'http://www.aclweb.org/anthology/J/J{}/'.format(query)
page = yield from get(url, compress=True)
magnet = first_magnet(page)
print('{}: {}'.format(query, magnet))
distros = range(80,90)
loop = asyncio.get_event_loop()
f = asyncio.wait([print_magnet(d) for d in distros])
loop.run_until_complete(f)
我可以确认代码卡在 Python 3.6.1 for Windows。
看起来问题与 compress=True
参数有关。如果删除它,代码将正常完成。
我认为你应该向 aiohttp 报告这个错误 issue tracker。
我试图运行其中的一个例子 page。由于某种原因它不起作用,如果你 运行 这个程序它会打印随机数量的 "hi" 然后它会卡住。我正在使用 python 3.6.0,你能帮我找出问题所在吗?
import asyncio
import aiohttp
import bs4
@asyncio.coroutine
def print_page(url):
response = yield from aiohttp.request('GET', url)
body = yield from response.text()
print(body)
@asyncio.coroutine
def get(*args, **kwargs):
response = yield from aiohttp.request('GET', *args, **kwargs)
return (yield from response.text())
def first_magnet(page):
return "hi"
@asyncio.coroutine
def print_magnet(query):
url = 'http://www.aclweb.org/anthology/J/J{}/'.format(query)
page = yield from get(url, compress=True)
magnet = first_magnet(page)
print('{}: {}'.format(query, magnet))
distros = range(80,90)
loop = asyncio.get_event_loop()
f = asyncio.wait([print_magnet(d) for d in distros])
loop.run_until_complete(f)
我可以确认代码卡在 Python 3.6.1 for Windows。
看起来问题与 compress=True
参数有关。如果删除它,代码将正常完成。
我认为你应该向 aiohttp 报告这个错误 issue tracker。