Can SQLAlchemy be configured to be non-blocking?

后端 未结 3 1219
南笙
南笙 2020-12-08 00:29

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 n

3条回答
  •  鱼传尺愫
    2020-12-08 01:31

    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/

    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.

提交回复
热议问题