|
From: Wagener, J. J <Joh...@st...> - 2007-08-25 21:48:42
|
Hi everyone,
Firstly - sorry for the lengthy email.
python.exe crashes on my machine when creating/closing cursors in a loop,=
=20creating multiple cursors along with a commit etc. I run windows xp, p=
ython 2.5, mingw32.
here's a simplified version of the code that still crashes:
<code>
import DB2
conn =3D DB2.connect(dsn=3D'STATS', uid=3D***, pwd=3D***)
for i in range(100):
=20 curs =3D conn.cursor()
=20 curs.execute("SELECT COUNT(*) FROM SYSIBM.SYSTABLES WITH UR;")
=20 print curs.fetchone()
conn.close()=20
</code>
the loop runs 26 times before I get a windows message that reads:
The instruction at "0x792ae24" referenced memory at "0x00000006". The me=
mory could not be read.
I've experimented with the code and I get it to work if I create the curs=
or before the loop instead of inside the loop(only one cursor object). =20
I've also tried creating the cursor objects in a dictionary so that I do =
not use the same cursor name over and over. This seems to work and the c=
ode executes fine - but as soon as conn.close() is called I get the same =
error. I ran a trace and it looks like the crash happens when the cursor=
=20objects have to be deleted from memory.
I tried many different things - but it looks like things go belly up when=
:
- more than one connection is created in one script.=20
So this does not work:
<code>
import DB2
conn =3D DB2.connect(dsn=3D'STATS', uid=3D'***', pwd=3D'***')
curs =3D conn.cursor()
for i in range(100):
=20 curs.execute("SELECT COUNT(*) FROM SYSIBM.SYSTABLES WITH UR;")
=20 print curs.fetchone()
=20 =20
conn.close()
conn2 =3D DB2.connect(dsn=3D'STATS', uid=3D'***', pwd=3D'***')
curs2 =3D conn2.cursor()
for i in range(100):
=20 curs2.execute("SELECT COUNT(*) FROM SYSIBM.SYSTABLES WITH UR;")
=20 print curs2.fetchone()
=20 =20
conn2.close()
</code>
- more than one cursor is created, along with a commit() in one script.=20
So this does not work:
<code>
import DB2
conn =3D DB2.connect(dsn=3D'STATS', uid=3D'***', pwd=3D'***')
curs =3D conn.cursor()
curs2 =3D conn.cursor()
for i in range(100):
=20 curs.execute("SELECT COUNT(*) FROM SYSIBM.SYSTABLES WITH UR;")
=20 print curs.fetchone()
=20 =20
conn.commit()
conn.close()
</close>
If I remove the commit() statement the code runs though. I can send a tra=
ce if requested.
I know that the above code looks silly - but this problem occurred as I w=
as selecting from one database, and inserting to another. That's when I =
started experimenting with=20
different combinations of things.=20
So this does not work:
<code>
import DB2
conn =3D DB2.connect(dsn=3D'STATS', uid=3D'***', pwd=3D'***')
conn2 =3D DB2.connect(dsn=3D'GTS', uid=3D'***', pwd=3D'***')
curs =3D conn.cursor()
curs2 =3D conn2.cursor()
for i in range(100):
=20 curs.execute("SELECT COUNT(*) FROM SYSIBM.SYSTABLES WITH UR;")
=20 curs2.execute("INSERT INTO MQUSER.TEST1 VALUES(1);")
=20 print curs.fetchone()
conn.close()
conn2.close()
</code
But this does - strange:
<code>
import DB2
conn =3D DB2.connect(dsn=3D'STATS', uid=3D'***', pwd=3D'***')
conn2 =3D DB2.connect(dsn=3D'GTS', uid=3D'***', pwd=3D'***')
curs =3D conn.cursor()
curs2 =3D conn2.cursor()
for i in range(100):
=20 curs.execute("SELECT COUNT(*) FROM SYSIBM.SYSTABLES WITH UR;")
=20 curs2.execute("INSERT INTO MQUSER.TEST1 VALUES(1);")
=20 print curs.fetchone()
=20 conn2.commit()
conn.close()
conn2.close()
</code>
I'm blasted for options at this stage. The route I have taken is to writ=
e the INSERT queries to a file in the script, and then do the inserts fro=
m the command line.
My other options are to try and build the library with another compiler o=
r even use a different version of python.
Any help or advice would be appreciated.
Thanks.
H.
_________________________________________________________________________=
_________________________________________________________
Standard Bank Disclaimer and Confidentiality Note
This e-mail, its attachments and any rights attaching hereto are, unless =
the context clearly indicates otherwise, the property of Standard Bank Gr=
oup Limited
and/or its subsidiaries ("the Group"). It is confidential, private and in=
tended for the addressee only. Should you not be the addressee and receiv=
e this e-mail by
mistake, kindly notify the sender, and delete this e-mail, immediately an=
d do not disclose or use same in any manner whatsoever. Views and opinion=
s
expressed in this e-mail are those of the sender unless clearly stated as=
=20those of the Group. The Group accepts no liability whatsoever for any =
loss or
damages whatsoever and howsoever incurred, or suffered, resulting, or ari=
sing, from the use of this email or its attachments. The Group does not w=
arrant the integrity
of this e-mail nor that it is free of errors, viruses, interception or in=
terference. Licensed divisions of the Standard Bank Group are authorised =
financial services providers
in terms of the Financial Advisory and Intermediary Services Act, No 37 o=
f 2002 (FAIS).
For information about the Standard Bank Group Limited visit our website h=
ttp://www.standardbank.co.za
_________________________________________________________________________=
__________________________________________________________
|