![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python 高级
进阶
东贝鸟
金庸
展开
-
python event
这次的代码,第一,列表推导式,第二就是 继承后的 t.start()import threadingfrom time import sleep# event = threading.Event()## event.clear() # 重置event对象## event.wait() # 阻塞线程 等待 event.set() 命令## event.set() # 发送指令class My(threading.Thread): def __init__(s原创 2020-07-08 22:20:10 · 716 阅读 · 0 评论 -
python线程池ThreadPoolExecutor,传单个参数和多个参数
这是线程池传单个参数的from concurrent.futures import ThreadPoolExecutor,as_completeddef test(a): print(a)qq = {"a":"1","b":"2","c":"3"}with ThreadPoolExecutor() as pool: for j ,k in qq.items(): res = pool.submit(test,j) kk = res.resul原创 2022-01-24 14:18:32 · 10817 阅读 · 1 评论 -
迭代器对象
迭代器对象就是实现了–next–方法和 --iter–方法的,缺一不可迭代器对象一点是可迭代对象反之就不一定了迭代器实现了工厂模式。实现了懒加载,节约了内存空间。我的理解就是,只给一个开头,后面的随用随取。不像可迭代对象。给了开头和结尾from itertools import counta = count(start=10)print(next(a))print(next(a))print(next(a))print(next(a))print(next(a))print(next(原创 2020-08-26 15:40:24 · 415 阅读 · 0 评论 -
可迭代对象
可迭代对象就是实现了 __iter__或者 __getitem__中的任意一个,可以通过下标索引的,可以通过 for 循环遍历的如何判断呢方法有两个,一个是这个用的少from collections import Iterableprint(isinstance([],Iterable))class test: passprint(isinstance(test(),Iterable))这个用的多一点上面说了,实现了__iter__或者 __getitem__就是原创 2020-08-26 14:36:00 · 170 阅读 · 0 评论 -
进程池
from time import sleepimport multiprocessingdef get_html(t): sleep(t) print('{}执行可以'.format(t)) return tif __name__ == '__main__': # 通过 cpu_count() 获取当前主机的核心数 pool = multiprocessing.Pool(multiprocessing.cpu_count()) result = po原创 2020-08-12 14:58:11 · 117 阅读 · 0 评论 -
线程池
from concurrent.futures import ThreadPoolExecutorfrom time import sleepexec = ThreadPoolExecutor(max_workers = 3)def get_time(t): sleep(t) print('获取{}'.format(t)) return ttas = exec.submit(get_time,1)tas2 = exec.submit(get_time,3)tas3原创 2020-08-11 16:32:27 · 126 阅读 · 0 评论 -
threading.Condition
import threading# 创建一个 condition 对象cond = threading.Condition()class kb(threading.Thread): def __init__(self,cond , name): threading.Thread.__init__(self,name = name) self.cond = cond def run(self): self.cond.acquire()原创 2020-08-11 15:20:36 · 241 阅读 · 0 评论 -
thread(高级)
import threadingimport requests# def get_url(url):# user_age = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"# head = {# 'User-Agent': user_age# }# req =原创 2020-07-08 21:52:28 · 307 阅读 · 0 评论 -
thread (初级)
import threadingimport requestsdef get_url(url): user_age = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" head = { 'User-Agent': user_age } req = requests.ge原创 2020-07-08 00:46:03 · 170 阅读 · 0 评论 -
Python 线程 join 和 Thread
from threading import Thread # 导入 进程包import time # 导入时间包#============ 这里总共有 3个线程 两个自己设置的线程 一个是主线程for i in range(5): print('主线程')def a(m): for i in ...原创 2019-10-31 21:08:22 · 147 阅读 · 0 评论 -
Python 中 socket 逐渐实现聊天室 (一)tcp
先做客户端import socket # 先引包client =socket.socket() # 定义一个变量,接收一个类型 ,接收是由 TCP 还是 UDP 连接 默认是TCPclient.connect(("localhost",9999)) # 确认好了网络连接类型后就是 ,确认连接的 地址 和 端口client.send('1qw34...原创 2019-10-30 21:03:45 · 1118 阅读 · 0 评论