是否可以从 Python (3.4) 异步查询 SQL Server? [英] Is it possible to asynchronously query SQL Server from Python (3.4)?

查看:45
本文介绍了是否可以从 Python (3.4) 异步查询 SQL Server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从 Python (3.4) 对 Microsoft SQL Server 执行异步查询,即在 asyncio 事件循环?

Is it possible to perform asynchronous queries against Microsoft SQL Server from Python (3.4), i.e. in the context of an asyncio event loop?

以下是一个骨架 asyncio 程序,其中(异步)SQL 查询应该被安装到 do_it 函数中:

The following is a skeleton asyncio program, where the (async) SQL query should be fitted into the do_it function:

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')

推荐答案

目前我发现的一个选择是商业产品 mxODBC Connect,不幸的是要花费数百美元.通过为 SQL Server 提供代理服务器,它能够支持异步调用.据说异步支持是通过 gevent 实现的,所以我不知道它对 asyncio 的适应程度如何.来自 Python 的 ODBC wiki,mxODBC 是唯一列出的支持异步的产品.

The one option I have found so far is the commercial product mxODBC Connect, which unfortunately costs several hundred dollars. By providing a proxy server to SQL Server, it is able to support asynchronous calls. Supposedly the async support is implemented via gevent, so I don't know how well it'll fit into asyncio. From Python's ODBC wiki, mxODBC is the only product listed with async support.

这篇关于是否可以从 Python (3.4) 异步查询 SQL Server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆