python 第十天
2016-01-15 21:46
501 查看
一、线程池
内容回顾: 1、考虑建立线程数量 min
2、线程池的状态
3、关闭线程
paramikle 里面demo.py interactive.py
http://www.cnblogs.com/wupeiqi/articles/4839959.html
例子:举例说明多线程#多线程
数据库插入时values(%s),%s只能是s不能是其他的
cur.lastrowid()新增的自增ID号是多少。
插入一条数据execute
插入多条数据executemany
conn.commit() 提交插入结果,否则插入不进去
cur.fetchone:取第一条数据
cur.fetchmany(8):获取前8条数据
cur.scroll():相对移动,负值朝上移动,正直朝下移动
cur.absolute:绝对移动
cur.fetchall:取所有的数据。
内容回顾: 1、考虑建立线程数量 min
2、线程池的状态
3、关闭线程
paramikle 里面demo.py interactive.py
http://www.cnblogs.com/wupeiqi/articles/4839959.html
例子:举例说明多线程#多线程
#coding=utf-8 import threading #进口threading from time import sleep import time def task1(): print ("Task 1 executed." ) sleep(1) def task2(): print ("Task 2 executed." ) sleep(5) print("多线程:") starttime=time.time(); #记录開始时间 threads = [] #创建一个线程列表,用于存放须要运行的子线程 t1 = threading.Thread(target=task1) #创建第一个子线程。子线程的任务是调用task1函数。注意函数名后不能有() threads.append(t1)#将这个子线程加入到线程列表中 t2 = threading.Thread(target=task2)#创建第二个子线程 threads.append(t2)#将这个子线程加入到线程列表中 for t in threads: #遍历线程列表 t.setDaemon(True) #将线程声明为守护线程。必须在start() 方法调用之前设置。假设不设置为守护线程程序会被无限挂起 t.start() #启动子线程 endtime=time.time();#记录程序结束时间 totaltime=endtime-starttime;#计算程序运行耗时 print ("耗时:{0:.5f}秒" .format(totaltime)); #格式输出耗时 print('---------------------------') #下面为普通的单线程运行过程。 print("单线程:") starttime=time.time(); task1(); task2(); endtime=time.time(); totaltime=endtime-starttime; print ("耗时:{0:.5f}秒" .format(totaltime));二、数据库
数据库插入时values(%s),%s只能是s不能是其他的
cur.lastrowid()新增的自增ID号是多少。
插入一条数据execute
插入多条数据executemany
conn.commit() 提交插入结果,否则插入不进去
cur.fetchone:取第一条数据
cur.fetchmany(8):获取前8条数据
cur.scroll():相对移动,负值朝上移动,正直朝下移动
cur.absolute:绝对移动
cur.fetchall:取所有的数据。
相关文章推荐
- python list循环语句的使用方法
- Python 文件读取与写入操作方法
- Python中函数的参数传递方式
- Python学习(三): 字符串操作
- python join字符连接函数的使用方法
- python的MySqldb使用
- python day11
- Python多线程学习
- Python MySQL API
- Python中pprint只有在足够长度的内容下才出效果
- python Eclipse开发环境搭建
- python之self
- python中的时间函数编写
- 第一次写python爬虫
- Windows下使用python虚环境
- Python中__init__方法使用
- Python 爬取CSDN博客频道
- Python json.dumps 中文乱码解决
- pyuv+python35的超简化异步编程方案,参考asyncio
- Python subprocess 死锁