#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/test@192.168.137.2/serv')
cursor = conn.cursor()
owner = "system"
def exp01():
writer = csv.writer(f, lineterminator="\n", 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="\n", 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="\n", 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="\n", 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="\n", 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="\n", 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="\n", 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="\n", 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="\n", 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="\n", 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="\n", 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="\n", 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="\n", 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="\n", 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
<Thread(exp01, started 140505364154112)><_MainThread(MainThread, started 140505545430784)>
select 'exp01' from dual
<Thread(exp02, started 140505353656064)>
select 'exp02' from dual
<_MainThread(MainThread, started 140505545430784)>
<_MainThread(MainThread, started 140505545430784)>
<Thread(exp03, started 140505343166208)>
select 'exp03' from dual
<Thread(exp04, started 140505332676352)><_MainThread(MainThread, started 140505545430784)>
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
<Thread(exp05, started 140505322186496)>
select 'exp05' from dual
<_MainThread(MainThread, started 140505545430784)>
<_MainThread(MainThread, started 140505545430784)>
<Thread(exp06, started 140505364154112)>
select 'exp06' from dual
<_MainThread(MainThread, started 140505545430784)>
<Thread(exp07, started 140505311696640)>
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
<Thread(exp08, started 140504956139264)>
select 'exp08' from dual
<_MainThread(MainThread, started 140505545430784)>
<Thread(exp09, started 140505332676352)>
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(MainThread, started 140505545430784)>
<_MainThread(MainThread, started 140505545430784)>
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: 非法的属性类型
<Thread(exp10, started 140505343166208)>
select 'exp10' from dual
<Thread(exp11, started 140504945649408)>
select 'exp11' from dual
<_MainThread(MainThread, started 140505545430784)>
<_MainThread(MainThread, started 140505545430784)>
<Thread(exp12, started 140505364154112)>
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: 用户请求取消当前的操作
<Thread(exp13, started 140504935159552)>
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(MainThread, started 140505545430784)>
<_MainThread(MainThread, started 140505545430784)>
<Thread(exp14, started 140504945649408)>
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 被调用当另外一个请求是正在处理
并发连接出现的错误
应该是单个连接同时对数据库进行了操作,尝试并发连接中!
python 多线程 公用一个连接
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:python 多线程另外一种写法
下一篇:python 多线程串行和并行
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Python中多线程、进程与协程编程
本文给出Python中多线程、进程与协程编程各自使用场景及使用基本思路总结。
Python 多线程 事件循环 多进程 协程 -
python 多线程中遍历 python多线程问题
一、前提: python的多线程的问题:GIL导致PYTHON 无法使用到计算机的多核,仅能使用单核 JAVA传统的多线程主要解决的问题: 1、运行于多核CPU上,各线程可分布于CPU的各个核心,让程序真正的并发 &n
python 多线程中遍历 python多线程 GIL python并发 多线程 -
python 多线程 多串口 python中多线程
一. 什么是线程 线程也是一种多任务编程的方式,可以使用计算机多核资源。线程又被称为轻量级的进程,线程具有以下特征:线程是计算机核心分配的最小单位一个进程可以包含多个线程线程也是一个运行过程,也要消耗计算机资源;多个线程共享其进程的资源和空间线程也拥有自己特有的资源属性,比如指令集,TID等线程无论创建、删除还是运行,资源消耗都小于进程多个线程之
python 多线程 多串口 Python多线程编程 全局解释器锁 GIL 封装个性化的线程类 __call__ -
JAVA多线程画图案例 java多线程应用实例
程序.进程.线程在操作系统中运行的程序就是进程,例如微信、IDE、QQ等(暴露年龄了?)一个进程中可以存在多个线程,如播放一个视频时有声音、图像、文字等等
JAVA多线程画图案例 多线程 java d3 System