摘要: imap imap_unordered 阅读全文
posted @ 2019-08-06 16:19 _simpleSmile 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 对于耗费cpu的操作,例如计算。多进程优于多线程 对于io操作,多线程优于多进程 阅读全文
posted @ 2019-08-05 20:08 _simpleSmile 阅读(424) 评论(0) 推荐(0) 编辑
摘要: as_completed map wait 阅读全文
posted @ 2019-08-05 19:37 _simpleSmile 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 每2秒弹出一组3个的 ‘got html text success’ Semaphore底层是用Condition实现的 阅读全文
posted @ 2019-08-04 16:50 _simpleSmile 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 4 # 条件变量,用于复杂的线程间同步 5 # 通过condition完成协同读诗 6 from threading import Lock 7 from threading import Condition 8 import threading 9 10 11 cla... 阅读全文
posted @ 2019-08-04 16:30 _simpleSmile 阅读(399) 评论(0) 推荐(0) 编辑
摘要: 1.用锁会影响性能 2.锁会引起死锁 RLock 阅读全文
posted @ 2019-08-04 14:58 _simpleSmile 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 1.线程通信方式--共享变量 缺点,共享变量需要加锁,来达到我们想要的效果 ps:不要去尝试去运行,我设置了while循环,而且没有设置守护线程。。。 2.通过queue的方式进行线程间的通信 阅读全文
posted @ 2019-08-03 14:45 _simpleSmile 阅读(370) 评论(0) 推荐(0) 编辑
摘要: 1.通过Thread类实例化 2.通过继承Thread来实现多线程 阅读全文
posted @ 2019-08-03 14:01 _simpleSmile 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 4 # gil global interpreter lock(cpython)全局解释器锁 5 # python中一个线程对应于c语言中的一个线程 6 # gil时的同一时刻只有一个线程在一个cpu上执行字节码,无法将多个线程映射到多个cpu上执行 7 # gil会根据执行的... 阅读全文
posted @ 2019-08-03 13:09 _simpleSmile 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 4 # requests -> urllib -> socket 5 import socket 6 from urllib.parse import urlparse 7 8 9 def get_url(url): 10 # 通过socket请求html 11 ... 阅读全文
posted @ 2019-08-01 17:20 _simpleSmile 阅读(331) 评论(0) 推荐(0) 编辑