日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

asyncio oracle 异步,带有asyncio futures和RuntimeError的InvalidStateError与aiohttp时使用期货回调...

發布時間:2024/9/27 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 asyncio oracle 异步,带有asyncio futures和RuntimeError的InvalidStateError与aiohttp时使用期货回调... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我是asyncio和aiohttp新手。我目前得到這個錯誤,不知道為什么我收到InvalidStateError我asyncio未來RuntimeError為我的會議:帶有asyncio futures和RuntimeError的InvalidStateError與aiohttp時使用期貨回調

Traceback (most recent call last):

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 184, in _run_module_as_main

"__main__", mod_spec)

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 85, in _run_code

exec(code, run_globals)

File "/Users/bli1/Development/QE/idea/trinity-tracer/tracer/tests/tracer.py", line 100, in

sys.exit(main(sys.argv))

File "/Users/bli1/Development/QE/idea/trinity-tracer/tracer/tests/tracer.py", line 92, in main

poster.post()

File "/Users/bli1/Development/QE/idea/trinity-tracer/tracer/utils/poster.py", line 87, in post

results = event_loop.run_until_complete(self.async_post_events(events))

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete

return future.result()

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/futures.py", line 274, in result

raise self._exception

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/tasks.py", line 239, in _step

result = coro.send(None)

File "/Users/bli1/Development/QE/idea/trinity-tracer/tracer/utils/poster.py", line 79, in async_post_events

task.add_done_callback(self.send_oracle, task.result(), session)

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/futures.py", line 268, in result

raise InvalidStateError('Result is not ready.')

asyncio.futures.InvalidStateError: Result is not ready.

Task exception was never retrieved

future: exception=RuntimeError('Session is closed',)>

Traceback (most recent call last):

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/tasks.py", line 239, in _step

result = coro.send(None)

File "/Users/bli1/Development/QE/idea/trinity-tracer/tracer/utils/poster.py", line 64, in async_post_event

async with session.post(self.endpoint, data=event) as resp:

File "/Users/bli1/Development/QE/idea/trinity-tracer/lib/python3.5/site-packages/aiohttp/client.py", line 565, in __aenter__

self._resp = yield from self._coro

File "/Users/bli1/Development/QE/idea/trinity-tracer/lib/python3.5/site-packages/aiohttp/client.py", line 161, in _request

raise RuntimeError('Session is closed')

RuntimeError: Session is closed

我所試圖做的是POST到端點,然后使用相同的事件POST編輯發布到另一個端點。這將是跑了作為另一async方法作為callback

這里是我的代碼:

async def async_post_event(self, event, session):

async with session.post(self.endpoint, data=event) as resp:

event["tracer"]["post"]["timestamp"] = time.time() * 1000.0

event["tracer"]["post"]["statusCode"] = await resp.status

return event

async def send_oracle(self, event, session):

async with session.post(self.oracle, data=event) as resp:

return event["event"]["event_header"]["event_id"], await resp.status

async def async_post_events(self, events):

tasks = []

conn = aiohttp.TCPConnector(verify_ssl=self.secure)

async with aiohttp.ClientSession(connector=conn) as session:

for event in events:

task = asyncio.ensure_future(self.async_post_event(event, session))

task.add_done_callback(self.send_oracle, task.result(), session)

tasks.append(task)

return await asyncio.gather(*tasks)

def post(self):

event_loop = asyncio.get_event_loop()

try:

events = [self.gen_random_event() for i in range(self.num_post)]

results = event_loop.run_until_complete(self.async_post_events(events))

print(results)

finally:

event_loop.close()

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的asyncio oracle 异步,带有asyncio futures和RuntimeError的InvalidStateError与aiohttp时使用期货回调...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。