python 多线程另外一种写法
来源:互联网 发布:poi导入excel数据库 编辑:程序博客网 时间:2024/06/03 06:18
import threadingfrom time import sleep,ctimeimport cx_Oracleimport timeloops=[9,5]def exp1(): 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(10) cursor.close() conn.close()def exp2(): 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(10) cursor.close() conn.close()def exp3(): 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(10) cursor.close() conn.close()def exp4(): 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(10) cursor.close() conn.close()def exp5(): 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(10) cursor.close() conn.close()def exp6(): 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(10) cursor.close() conn.close()def main(): print 'starting at:',ctime() threads=[] nloops=[exp1,exp2,exp3,exp4,exp5,exp6] abs=range(len(nloops)) j=0 for i in nloops: a = "%s%s" % ('exp_thread', i) t=threading.Thread(target=i,name=a) threads.append(t) j = j + 1 print threads for i in abs: print threading.current_thread() threads[i].start() for i in abs: threads[i].join() print threading.current_thread() print 'all Done at:',ctime()if __name__=='__main__': main()C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/thread/p12.pystarting at: Thu Sep 14 08:28:18 2017[<Thread(exp_thread<function exp1 at 0x025ACE30>, initial)>, <Thread(exp_thread<function exp2 at 0x0262B5F0>, initial)>, <Thread(exp_thread<function exp3 at 0x0262B630>, initial)>, <Thread(exp_thread<function exp4 at 0x0262B670>, initial)>, <Thread(exp_thread<function exp5 at 0x0262B6B0>, initial)>, <Thread(exp_thread<function exp6 at 0x0262B6F0>, initial)>]<_MainThread(MainThread, started 9852)><_MainThread(MainThread, started 9852)><_MainThread(MainThread, started 9852)><_MainThread(MainThread, started 9852)><_MainThread(MainThread, started 9852)><_MainThread(MainThread, started 9852)><Thread(exp_thread<function exp1 at 0x025ACE30>, started 9340)>select 'exp01' from dual<Thread(exp_thread<function exp2 at 0x0262B5F0>, started 8780)>select 'exp02' from dual<Thread(exp_thread<function exp6 at 0x0262B6F0>, started 8940)>select 'exp06' from dual<Thread(exp_thread<function exp4 at 0x0262B670>, started 9488)>select 'exp04' from dual<Thread(exp_thread<function exp3 at 0x0262B630>, started 8420)>select 'exp03' from dual<Thread(exp_thread<function exp5 at 0x0262B6B0>, started 4684)>select 'exp05' from dual<_MainThread(MainThread, started 9852)><_MainThread(MainThread, started 9852)><_MainThread(MainThread, started 9852)><_MainThread(MainThread, started 9852)><_MainThread(MainThread, started 9852)><_MainThread(MainThread, started 9852)>all Done at: Thu Sep 14 08:28:28 2017Process finished with exit code 0
阅读全文
0 0
- python 多线程另外一种写法
- 另外一种写法如下:
- ALV的另外一种写法
- 数组的另外一种写法
- HDU 1232 另外一种写法
- json的另外一种写法
- JSP删除链接的另外一种写法
- 死循环的另外一种写法
- 左右连接的另外一种写法
- Crontab的另外一种写法(@reboot, @yearly...)
- angularjs-controller的另外一种写法
- curl的另外一种简便写法
- Unity For循环另外一种写法
- python yield 另外一种用法
- 关于Mysql中in参数变量的另外一种写法
- iOS中另外一种多线程实现方式NSOperation
- 另外一种累
- python编程(一种自定义定时器的写法)
- 2017/09/13
- String.equals报java.lang.NullPointerException
- JS字符串转Byte[]
- dataguard归档不同步的问题解决思路及步骤
- Java中锁概念总结
- python 多线程另外一种写法
- java 小数点 四舍五入 方法
- Linux_OS_code_to_sum_up(Linux系统编程总结)
- 浅谈WebLogic和Tomcat
- 第二周项目二 程序的多文件组织
- JS 中的事件绑定、事件监听、事件委托是什么?
- jQuery滑动tab选项卡
- 加密解密算法java实现(3)—RSA --纯java.
- 【安全牛学习笔记】 端口扫描