我遇到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'
>>>
<code><pre>
###############################################################
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')
</code></pre>
答案 0 :(得分:0)
如果您怀疑cx_Oracle中存在错误,请在此处记录问题:https://github.com/oracle/python-cx_Oracle/issues。
我使用您的示例查看了代码,确实存在内存泄漏,我刚刚插入。谢谢你报告这个!