是否可以从 Python (3.4) 对 Microsoft SQL Server 执行异步查询,即在 asyncio 的上下文中事件循环?
以下是一个基本的异步程序,其中(异步)SQL 查询应该安装到 do_it
函数中:
import asyncio
import contextlib
@asyncio.coroutine
def do_it():
# TODO: Make an asynchronous MS SQL query, but how??
fut = asyncio.Future()
fut.set_result(None)
return fut
with contextlib.closing(asyncio.SelectorEventLoop()) as loop:
asyncio.set_event_loop(loop)
loop.run_until_complete(do_it())
print('Finished')
最佳答案
目前只有 PostgreSQL native 异步支持通过 aiopg 库。
但是您可以通过 loop.run_in_executor()
运行对 MSSQL 的同步调用。
关于python - 是否可以从 Python (3.4) 异步查询 SQL Server?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24820025/