异步协同程序可用于调用。这包括其他协同程序、返回延迟的函数和返回的函数 awaitable objects 如 class MySpiderDeferred(Spider):
# ...
async def parse(self, response):
additional_response = await treq.get('https://additional.url')
additional_data = await treq.content(additional_response)
# ... use response and additional_data to yield items and requests
class MySpiderAsyncio(Spider):
# ...
async def parse(self, response):
async with aiohttp.ClientSession() as session:
async with session.get('https://additional.url') as additional_response:
additional_data = await additional_response.text()
# ... use response and additional_data to yield items and requests
注解 例如许多类库 aio-libs ,需要 注解 如果你想 异步代码的常见用例包括:
|
Archiver|手机版|笨鸟自学网 ( 粤ICP备20019910号 )
GMT+8, 2025-1-22 21:45 , Processed in 0.017058 second(s), 17 queries .