Python Django和SQL Server,符合gevent
我想在Django应用程序中使用SQL Server数据库,以便将来扩展 该应用程序将是I/O绑定的,因此我认为使其可伸缩的最好方法是将Gunicorn与gevent worker类一起使用 问题是,对于将Gunicorn与Python Django和SQL Server,符合gevent,python,sql-server,django,gunicorn,gevent,Python,Sql Server,Django,Gunicorn,Gevent,我想在Django应用程序中使用SQL Server数据库,以便将来扩展 该应用程序将是I/O绑定的,因此我认为使其可伸缩的最好方法是将Gunicorn与gevent worker类一起使用 问题是,对于将Gunicorn与--worker class gevent一起使用,Django应用程序应该与gevent兼容,并且通常会发生一些数据库客户端不兼容的情况(例如:mysqlclient lib) 我找到了Django的SQL Server后端: 但我无法理解它是否符合gevent(也称为“绿
--worker class gevent
一起使用,Django应用程序应该与gevent兼容,并且通常会发生一些数据库客户端不兼容的情况(例如:mysqlclient lib)
我找到了Django的SQL Server后端:
但我无法理解它是否符合gevent(也称为“绿色”)
我知道,如果它只使用标准的套接字/网络python libs(可以很容易地对其进行修补),情况会是这样,但我不明白情况是否如此。pyodbc SQL Server后端gevent兼容吗
在官方手册和谷歌上,我找不到更多信息。如果您愿意切换到Postgresql,我已经设置了一个模块,可以完成您需要的所有操作: 这包括一个连接池,用于同时处理数千个连接 **更新** 我有一个使用Pymssql的解决方案:
import gevent.socket
import pymssql
import traceback
import sys
def wait_callback(read_fileno):
gevent.socket.wait_read(read_fileno)
pymssql.set_wait_callback(wait_callback)
def conn():
return pymssql.connect(server=server, user=user, password=password, autocommit=True)
def fetchone(SQL, *args):
with conn() as c:
with c.cursor() as cursor:
try:
cursor.execute(SQL, args)
except TypeError:
cursor.execute(SQL, args[0])
except Exception as exc:
print(sys._getframe().f_back.f_code)
print(sys._getframe().f_back.f_code.co_name)
traceback.print_exc()
return ()
return cursor.fetchone()
def fetchall(SQL, *args):
with conn() as c:
with c.cursor() as cursor:
try:
cursor.execute(SQL, args)
except TypeError:
cursor.execute(SQL, args[0])
except Exception as exc:
print(sys._getframe().f_back.f_code)
print(sys._getframe().f_back.f_code.co_name)
traceback.print_exc()
return ()
return cursor.fetchall()
def execute(PSQL, *args):
with conn() as c:
with c.cursor() as cursor:
try:
cursor.execute(PSQL, args)
except TypeError:
cursor.execute(PSQL, args[0])
except ValueError:
cursor.execute(PSQL, tuple(args[0]))
except:
print(sys._getframe().f_back.f_code)
print(sys._getframe().f_back.f_code.co_name)
traceback.print_exc()
return ()
finally:
return cursor.close()
谢谢,由于某些原因,我这次更喜欢sql server,但我非常感谢您为未来项目提供的解决方案