我对python cx_Oracle模块有问题
通过现有游标重复执行查询(可能使用
不同的参数)会导致巨大的内存泄漏
下面是一个简单的例子。在
查询执行的两个变体-mleak1和mleak2,有准备和没有准备的工作方式相同
Python3号和Python2号都存在同样的问题
在每个查询修复泄漏后重新打开游标
类似的postgres版本也可以
这是cx®Oracle模块中的错误吗?在
这个问题在两台完全不同的机器上重现了logname@machine1(ubuntu_16.04):~> python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> cx_Oracle.__version__
'6.0rc2'
>>>
[logname@machine2]$ python3
Python 3.5.1 (default, Oct 22 2016, 08:10:47)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> cx_Oracle.__version__
'6.0'
>>>
###############################################################
import cx_Oracle
import psycopg2
sql_text="select 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' from dual"
def mleak1(connect_string_ora ):
with cx_Oracle.connect(connect_string_ora) as dbo:
ora_cursor=dbo.cursor()
for i in range(0,10000000):
ora_cursor.execute(sql_text)
for r in ora_cursor:
print (r)
def mleak2(connect_string_ora ):
with cx_Oracle.connect(connect_string_ora) as dbo:
ora_cursor=dbo.cursor()
ora_cursor.prepare(sql_text)
for i in range(0,10000000):
ora_cursor.execute(None)
for r in ora_cursor:
print (r)
def no_mleak(connect_string_pg ):
with psycopg2.connect(connect_string_pg) as dbp:
pg_cursor=dbp.cursor()
pg_cursor.execute("create table dual(f) as select 1") #to mimics oracle sql text query
for i in range(0,10000000):
pg_cursor.execute(sql_text)
for r in pg_cursor:
print (r)
mleak1('scott/tiger')
#mleak2('scott/tiger')
#no_mleak('password=xxx dbname=mydb user=myuser')