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 ...
随机推荐
- jQuery之基础核心(demo)
jQuery之基础核心 作者的热门手记 jQuery之基础核心(demo) 本文主要简单的介绍下jQuery一些基础核心,大致了解jQuery使用模式.适用于有HTML.CSS.javas ...
- uWSGI+Django (中)
环境是ubuntu 14.0 python3 django 1.10 1:安装uwsgi sudo apt-get install libpcre3 libpcre3-dev sudo pip3 i ...
- django登录逻辑
django-restframework中已经实现了登录逻辑,只需要安装配置就可以使用 pip install djangorestframework-jwt REST_FRAMEWORK = { ' ...
- 谷歌chrome浏览器vue调试工具vue-devtools的安装
先导 vue-devtools是一款基于chrome浏览器的插件,用于vue应用的调试,这款vue调试神器可以极大地提高我们的调试效率.帮助我们快速的调试开发vue应用. 第一步: 我们可以先从git ...
- C语言题库----指针
1.如果f是一个函数,请说明 f() 和f的意思. f是函数的地址,f()是函数 2.怎样理解数组的下标运算? 先偏移,后取址. 3.int *p,*q; int a[]={10,20,30,40}; ...
- sql server 与 sql server compact 互相数据导入
从SQL Server 导出数据到 Sql Compact 使用 Sql Server Compact Tool box 从SQL Server Comapct 导出数据到 Sql Server 使 ...
- Java中List集合去除重复数据的方法
1. 循环list中的所有元素然后删除重复 public static List removeDuplicate(List list) { for ( int i = 0 ; i < list. ...
- Day 22 初识面向对象
一.两种编程思想 1.面向过程编程 核心是'过程',过程指的是解决问题的步骤,就是先干什么再干什么 基于面向过程思想编写程序相当于写一条流水线,是一种机械式的思维方式 优点:解决问题的思路清晰,可以把 ...
- Angular2+AngularJS
AngularJS 系列: 1.angular.module 的定义 var mapApp = angular.module("positionSalaryEditApp",[&q ...
- Maven多项目继承:dependencyManagement scope=import
maven的多项目结构中,可以使用parent定义起父项目,从而从父项目中继承依赖等属性.但是美中不足,maven只能单继承,即一个项目只能使用parent标签定一个父级项目. maven2.9之后的 ...