py库:threading
https://www.youtube.com/watch?v=DnTn3Yx-Nvg
join功能:
import threading
import time def thread_job2():
print('T2', threading.current_thread()) def thread_job1():
print("-----------T1 begin-----------")
for i in range(10):
print("job2:", threading.current_thread())
time.sleep(0.1)
print("-----------T1 end-----------") def main():
thread1 = threading.Thread(target=thread_job1, name="T1")
thread2 = threading.Thread(target=thread_job2, name="T2")
thread1.start()
thread2.start()
thread1.join() # 要等线程全部运行完,才执行下一步。需要加这一句
print(threading.active_count())
print(threading.enumerate())
print(threading.currentThread())
print("all done") if __name__ == '__main__':
main()
Queue功能
https://www.youtube.com/watch?v=DnTn3Yx-Nvg
https://github.com/MorvanZhou/tutorials/blob/master/threadingTUT/thread4_queue.py 代码
GIL
多线程的运算不一定会效率会提升很多,原因在于 python 的 GIL (global interpreter lock)
https://www.youtube.com/watch?v=2511-7VR4nQ
lock锁
https://www.youtube.com/watch?v=-q4txLdUMBM
https://github.com/MorvanZhou/tutorials/blob/master/threadingTUT/thread6_lock.py
lock和join的区别: lock 是锁住变量的更新,join 是不让主线程比某个 thread 先结束
多进程
多核可以避免上述多线程的劣势
https://morvanzhou.github.io/tutorials/python-basic/multiprocessing/3-queue/
...
py库:threading的更多相关文章
- tablib把数据导出为Excel、JSON、CSV等格式的Py库(写入数据并导出exl)
#tablib把数据导出为Excel.JSON.CSV等格式的Py库 #python 3 import tablib #定义列标题 headers = ('1列', '2列', '3列', '4列', ...
- py库: arrow (时间)
arrow是个时间日期库,简洁易用.支持python3.6 https://arrow.readthedocs.io/en/latest/ arrow官网api https://github.com/ ...
- py库: scrapy (深坑未填)
scrapy 一个快速高级的屏幕爬取及网页采集框架 http://scrapy.org/ 官网 https://docs.scrapy.org/en/latest/ Scrapy1.4文档 http: ...
- py库: Tesseract-OCR(图像文字识别)
http://blog.csdn.net/u012566751/article/details/54094692 Tesseract-OCR入门使用1 http://blog.csdn.net/u01 ...
- py库: django (web框架)
http://www.imooc.com/learn/736 Python-走进Requests库 http://www.imooc.com/learn/790 django入门与实践 http:// ...
- python语言线程标准库threading.local源码解读
本段源码可以学习的地方: 1. 考虑到效率问题,可以通过上下文的机制,在属性被访问的时候临时构建: 2. 可以重写一些魔术方法,比如 __new__ 方法,在调用 object.__new__(cls ...
- python 标准库 -- threading
threading : 提高对网络端口的读写效率. threading.Thread.start() 执行线程操作 threading.Thread.run() 执行线程操作 threading.Th ...
- 可以用py库: pyautogui (自动测试模块,模拟鼠标、键盘动作)来代替pyuserinput
PyAutoGUI 是一个人性化的跨平台 GUI 自动测试模块 pyUserInput模块安装前需要安装pywin32和pyHook模块.(想要装的看https://www.cnblogs.com/m ...
- py库: GUI(tkinter)
图形用户界面(Graphical User Interface,简称 GUI) http://www.runoob.com/python/python-gui-tkinter.html Python ...
随机推荐
- vue day4 table
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 虚拟机无法上网,没有eth0
虚拟机无法上网,找不到eth0解决方案如下: Ifconfig -a 第一步,输入如下命令,编辑对应文件(使用管理员权限执行,下同) # vim /etc/default/grub 在"GR ...
- CF999E Reachability from the Capital来自首都的可达性
题目大意: 有n个节点m条边,边都是单向的,请你添加最少的边使得起点s到其他与其他每一个点之间都能互相到达 这题一看就是一个缩点啊 其实对于原有的m条边相连的一些点,如果之前他们已经形成了强连通分量( ...
- 使用JenKins实现自动执行python脚本
1.使用Jenkins创建一个工程,工程主要配置项参照下图,其他配置项恢复默认 2.工程配置完成之后,点击[立即构建],执行完成后进入到控制台查看是否执行成功.
- (转)Unity_什么是Draw Call? 什么是Batch?
開發遊戲時,一定被時時提醒要減少 Draw Call,當然UNITY也不例外,打開Game Window裡的 Stats,可以看到 Draw Call 與 Batched 的數字.但到底甚麼是 Dra ...
- MySQL Execution Plan--IN子查询包含超多值引发的查询异常
问题描述 版本:MySQL 5.7.24 SQL语句: SELECT wave_no, SUM(IF(picking_qty IS NULL, 0, picking_qty)) AS PICKED_Q ...
- oracle中创建数据库用户,并授权
--查看表空间文件路径select * from dba_data_files where tablespace_name=$TABLESPACE CREATE TABLESPACE usr_aa D ...
- Ignite(三): Ignite VS Spark
参考:https://www.itcodemonkey.com/article/9613.html gnite 和 Spark,如果笼统归类,都可以归于内存计算平台,然而两者功能上虽然有交集,并且 I ...
- php使用select语句查询数据信息
<html> <head> <title>Finding User</title> </head> <body> <h2& ...
- Azure CosmosDB (10) Azure Cosmos DB体系结构
<Windows Azure Platform 系列文章目录> Azure Cosmos DB的体系结构分为以下几个部分: 1.Database Accounts Database Acc ...