如下所示:
#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") def exp01(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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 " 输出: C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/thread/p7.py <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <_MainThread(MainThread, started 156528)> <Thread(exp01, started 155004)> select 'exp01' from dual <Thread(exp12, started 155744)> select 'exp12' from dual<Thread(exp02, started 155000)> select 'exp02' from dual <Thread(exp08, started 155728)> select 'exp08' from dual <Thread(exp06, started 155752)> select 'exp06' from dual <Thread(exp03, started 154816)> select 'exp03' from dual <Thread(exp09, started 156544)> select 'exp09' from dual <Thread(exp11, started 155760)> select 'exp11' from dual <Thread(exp04, started 154112)> select 'exp04' from dual <Thread(exp10, started 155764)><Thread(exp05, started 154640)> select 'exp10' from dualselect 'exp05' from dual <Thread(exp07, started 155188)> select 'exp07' from dual <Thread(exp13, started 154600)> select 'exp13' from dual <Thread(exp14, started 155804)> select 'exp14' from dual SID SERIAL# USERNAME PREV_SQL_ID 1 9 1179 TEST 01tjnxmmurdw7 2 10 75 TEST g5ph474nsjvwv 3 12 907 TEST 87mdhpgj9k5tz 4 419 1303 TEST 4g8r4bkf8aq3n 5 420 655 TEST 1rx9mjdvp1udx 6 421 1955 TEST 928r7khrtn4jd 7 424 51 TEST d6sgjjwpm74qz 8 839 3 TEST a1hg7hrwgrdqk 9 840 43 TEST fqjuj4qp5hmf0 10 841 111 TEST 2jzx0889h3k5n 11 1252 145 TEST awtzfbx7dhn88 12 1253 7 TEST 55tzs9gdmcd4p 13 1254 9 TEST 4v01fvb5sj7k4 14 1255 265 TEST 39bcsfjr5y62b 此时是并发执行 改变join的位置: #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") def exp01(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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(): conn = cx_Oracle.connect('test/test@192.168.137.2/serv') cursor = conn.cursor() owner = "system" 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 " C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/thread/p7.py <_MainThread(MainThread, started 154776)> <Thread(exp01, started 156240)> select 'exp01' from dual 此时变成串行,数据库连接也只有一个: SID SERIAL# USERNAME PREV_SQL_ID 1 421 1957 TEST 928r7khrtn4jd
以上这篇python 多线程串行和并行的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年11月26日
2024年11月26日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]