Python Package(1)Async
asyncio
import asyncio
loop = asyncio.get_event_loop()
for record in event['Records']:
message = json.loads(record['Sns']['Message'])
loop.run_until_complete(asyncio.gather(meeting.incoming_msg(message['action'], message)))
return
It will keep sending messages to run, it will not blocking the main thread.
References:
https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432090954004980bd351f2cd4cc18c9e6c06d855c498000
https://segmentfault.com/a/1190000008814676
asyncio
import asyncio
loop = asyncio.get_event_loop()
for record in event['Records']:
message = json.loads(record['Sns']['Message'])
loop.run_until_complete(asyncio.gather(meeting.incoming_msg(message['action'], message)))
return
It will keep sending messages to run, it will not blocking the main thread.
References:
https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432090954004980bd351f2cd4cc18c9e6c06d855c498000
https://segmentfault.com/a/1190000008814676
本文介绍了一个使用Python的asyncio库实现的异步消息处理方法。通过获取事件记录并解析消息内容,利用asyncio的特性非阻塞地处理每一个传入的消息,确保主线程不被阻塞。这种方式适用于需要高效处理大量并发消息的应用场景。
517

被折叠的 条评论
为什么被折叠?



