[英]Call async function in Enum
I want to refactor my code from sync to async.我想将我的代码从同步重构为异步。 I use python and FastApi.
我使用 python 和 FastApi。 I use the method which calls async function in Enumaration.
我使用枚举中调用异步函数的方法。
for example:例如:
from enum import Enum
from app.story import get_story
StoriesEnum = Enum(
"StoriesEnum", {story: story for story in get_story.story_list},
)
As per the documentation<\/a> :根据
文档<\/a>:
<\/blockquote>
Thus, what you could do is:因此,您可以做的是:
import asyncio async def go(): s = await get_story() s_list = s.story_list # ... asyncio.run(go())<\/code><\/pre>
PS It would really help though, if you provided a minimal reproducible example<\/a> . PS 如果您提供了一个
"最小的可重现示例<\/a>,它确实会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.