PythonAsyncio由于某种原因被卡住了

PythonAsyncio由于某种原因被卡住了,python,web-crawler,python-asyncio,Python,Web Crawler,Python Asyncio,我试着从这个例子中运行一个 . 由于某些原因,它不工作,如果你运行这个程序,它将打印随机数量的“嗨”,然后它将卡住。我正在使用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 res

我试着从这个例子中运行一个 . 由于某些原因,它不工作,如果你运行这个程序,它将打印随机数量的“嗨”,然后它将卡住。我正在使用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上的代码stuck

看起来问题与
compress=True
param有关。如果删除它,代码将很好地完成


我认为您应该向aiohttp报告此错误。

我可以确认Python 3.6.1 for Windows上的代码错误

看起来问题与
compress=True
param有关。如果删除它,代码将很好地完成


我认为您应该向aiohttp报告此错误。

返回(从response.text()获得收益)
听起来很奇怪……您的代码对我来说很好,程序在打印了十次后正确返回。此外,如果使用Python >=3.5,请考虑使用语法。<代码>返回(来自Real.Trand)的代码> <代码>对我来说听起来很奇怪……您的代码对我来说很好,程序在打印<代码> 8x:Hi/<代码>十次之后正确返回。此外,如果使用Python >=3.5,请考虑使用语法。