擅长:python、mysql、java
<p>由于<a href="https://stackoverflow.com/users/3652949/py-dude">@py_dude</a><a href="https://stackoverflow.com/a/58996863/1305461">mentioned</a>,<code>Flask</code>不支持异步调用。如果您正在寻找一个功能和感觉类似于<code>Flask</code>但是异步的库,我建议您签出<a href="https://sanic.readthedocs.io/en/latest/" rel="nofollow noreferrer">^{<cd3>}</a>。下面是一些示例代码:</p>
<pre class="lang-py prettyprint-override"><code>from sanic import Sanic
from sanic.response import json
app = Sanic()
@app.route("/")
async def test(request):
return json({"hello": "world"})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
</code></pre>
<p>异步更新数据库应该不是问题;请参阅<a href="https://github.com/timofurrer/awesome-asyncio#database-drivers" rel="nofollow noreferrer">here</a>以查找支持异步的数据库驱动程序。要处理文件,请签出<a href="https://github.com/Tinche/aiofiles" rel="nofollow noreferrer">^{<cd4>}</a>。如果异步运行,您可以在单个线程上非常快速地运行服务器,而不会出现任何问题。在</p>