python - 是否可以从 Python (3.4) 异步查询 SQL Server?

标签 python sql-server asynchronous python-3.4 python-asyncio

是否可以从 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/

相关文章:

python - 为什么 scrapy 在尝试抓取和解析网站时会为我抛出错误?

sql - sql中的高级单词搜索

mysql - Sql 将十六进制日期转换为 mysql varchar(date)

java - 如何处理多个 ListenableFuture? ( Spring )

Python - 十进制到整数低字节然后高字节

python - Pandas - 散点矩阵集标题

python - 使用 pytest 运行测试时如何在 PyCharm 中查看运行时警告?

sql-server - 是否可以在命令行上将参数传递给 .dtsx 包?

swift 3 : capture strong self in @escaping closure without asynchronous work

javascript - 异步加载 Google Maps API