pythonマルチスレッド共通接続


#coding=utf-8
import threading
import time
import cx_Oracle
from pprint import pprint
import csv
table_name = "dbtest.csv"
f = open(table_name + ".csv", "w")
conn = cx_Oracle.connect('test/[email protected]/serv')
cursor = conn.cursor()
owner = "system"
def exp01():
    writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp01' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp02(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp02' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp03(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp03' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp04(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp04' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp05(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp05' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp06(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp06' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp07(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp07' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp08(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp08' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp09(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp09' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp10(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp10' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp11(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp11' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp12(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp12' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp13(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp13' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() def exp14(): writer = csv.writer(f, lineterminator="
", quoting=csv.QUOTE_NONNUMERIC) tname = threading.current_thread() print tname exportOracleSql = "select 'exp14' from dual" print exportOracleSql x = cursor.execute(exportOracleSql) time.sleep(1000) cursor.close() conn.close() threads = [] t1 = threading.Thread(target=exp01,name='exp01') threads.append(t1) t2 = threading.Thread(target=exp02,name='exp02') threads.append(t2) t2 = threading.Thread(target=exp03,name='exp03') threads.append(t2) t2 = threading.Thread(target=exp04,name='exp04') threads.append(t2) t2 = threading.Thread(target=exp05,name='exp05') threads.append(t2) t2 = threading.Thread(target=exp06,name='exp06') threads.append(t2) t2 = threading.Thread(target=exp07,name='exp07') threads.append(t2) t2 = threading.Thread(target=exp08,name='exp08') threads.append(t2) t2 = threading.Thread(target=exp09,name='exp09') threads.append(t2) t2 = threading.Thread(target=exp10,name='exp10') threads.append(t2) t2 = threading.Thread(target=exp11,name='exp11') threads.append(t2) t2 = threading.Thread(target=exp12,name='exp12') threads.append(t2) t2 = threading.Thread(target=exp13,name='exp13') threads.append(t2) t2 = threading.Thread(target=exp14,name='exp14') threads.append(t2) if __name__ == '__main__': for t in threads: #t.setDaemon(True) t.start() #t.run() #t.start() # print '3333333' print threading.current_thread() # print t.is_alive() # print '3333333' t.join() print "all over " [oracle@node01 python]$ python t100.py <_mainthread started=""> select 'exp01' from dual select 'exp02' from dual <_mainthread started=""> <_mainthread started=""> select 'exp03' from dual <_mainthread started=""> select 'exp04' from dual Exception in thread exp01: Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "t100.py", line 18, in exp01 x = cursor.execute(exportOracleSql) DatabaseError: DPI-1002: invalid OCI handle select 'exp05' from dual <_mainthread started=""> <_mainthread started=""> select 'exp06' from dual <_mainthread started=""> select 'exp07' from dual Exception in thread exp04: Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "t100.py", line 52, in exp04 x = cursor.execute(exportOracleSql) DatabaseError: DPI-1002: invalid dpiStmt handle select 'exp08' from dual <_mainthread started=""> Exception in thread exp03: Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "t100.py", line 41, in exp03 x = cursor.execute(exportOracleSql) OperationalError: ORA-01013: select 'exp09' from dual <_mainthread started=""> <_mainthread started=""> Exception in thread exp06: Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "t100.py", line 74, in exp06 x = cursor.execute(exportOracleSql) DatabaseError: ORA-24315: select 'exp10' from dual select 'exp11' from dual <_mainthread started=""> <_mainthread started=""> select 'exp12' from dual Exception in thread exp09: Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "t100.py", line 107, in exp09 x = cursor.execute(exportOracleSql) OperationalError: ORA-01013: select 'exp13' from dual Exception in thread exp10: Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "t100.py", line 118, in exp10 x = cursor.execute(exportOracleSql) OperationalError: ORA-03114: ORACLE Exception in thread exp11: Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "t100.py", line 129, in exp11 x = cursor.execute(exportOracleSql) OperationalError: ORA-03114: ORACLE Exception in thread exp12: Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "t100.py", line 140, in exp12 x = cursor.execute(exportOracleSql) DatabaseError: DPI-1002: invalid dpiStmt handle Exception in thread exp07: Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "t100.py", line 85, in exp07 x = cursor.execute(exportOracleSql) DatabaseError: ORA-24909: 。 <_mainthread started=""> <_mainthread started=""> select 'exp14' from dual Exception in thread exp14: Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "t100.py", line 162, in exp14 x = cursor.execute(exportOracleSql) OperationalError: ORA-03114: ORACLE all over Exception in thread exp13: Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "t100.py", line 151, in exp13 x = cursor.execute(exportOracleSql) OperationalError: ORA-03114: ORACLE Errors in file : OCI-21500: , : [17099], [], [], [], [], [], [], [] OCI-21500: , : [17099], [], [], [], [], [], [], [] Errors in file : OCI-21500: , : [17099], [], [], [], [], [], [], [] OCI-21500: , : [17099], [], [], [], [], [], [], [] ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.їїїїїїїїSegmentation fault (core dumped) DatabaseError: ORA-24909: 。 [oracle@node01 python]$ oerr ora 24909 24909, 00000, "call in progress. Current operation cancelled" // *Cause: The OCI call was invoked when another call on the connection was // in progress. // *Action: Check if the OCI call is supported when the call is in progress // under special conditions; for example, if it is being used by a // signal handler. // NLS_DO_NOT_TRANSLATE [24910,24910] [oracle@node01 python]$ OCI , !