可以SQLAlchem​​y的被配置为非阻塞? [英] Can SQLAlchemy be configured to be non-blocking?

查看:327
本文介绍了可以SQLAlchem​​y的被配置为非阻塞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是IM pression该数据库通过调用SQLAlchem​​y的将被阻塞,不适合在比同步code以外的任何使用情况下。我是正确的(我希望我不是!),或者有配置它是无阻塞的方式?

I'm under the impression that database calls through SQLAlchemy will block and aren't suitable for use in anything other than synchronous code. Am I correct (I hope I'm not!) or is there a way to configure it to be non-blocking?

推荐答案

您可以通过使用SQLA在非阻塞式的 GEVENT 。下面是使用psycopg2的,使用psycopg2的的协程支持一个例子:

You can use SQLA in a non-blocking style using gevent. Here's an example using psycopg2, using psycopg2's coroutine support:

https://bitbucket.org/zzzeek/green_sqla/

我还听说乡亲使用带有 pymysql 同样的想法。由于pymysql是纯Python,并使用套接字库,补丁GEVENT套接字库是异步的。

I've also heard folks use the same idea with pymysql. As pymysql is in pure Python and uses the sockets library, gevent patches the socket library to be asynchronous.

这篇关于可以SQLAlchem​​y的被配置为非阻塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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