python oracle爆内存,python cx_Oracle内存

我对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')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值