摘要: 一、多进程 1、多线程,多进程 多线程: 适用于io密集型任务 多进程 适用于cpu密集型任务 1 import multiprocessing,time,virtualenv 2 def down_load(): 3 time.sleep(5) 4 print('运行完了') 5 6 if __n 阅读全文
posted @ 2019-11-30 22:21 xmb 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 一、锁 1、多个线程操作同一个数据的时候,就的加锁 实例: import threading num = 0 lock = threading.Lock() #申请一把锁 def add(): global num #lock.acquire() #加锁 #num+=1 #lock.release( 阅读全文
posted @ 2019-11-30 22:08 xmb 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 一、守护线程 1、主线程结束,子线程立马结束 实例: 1 import threading,time 2 def down_load(): 3 time.sleep(5) 4 print('运行完了') 5 for i in range(10): 6 t = threading.Thread(tar 阅读全文
posted @ 2019-11-30 21:59 xmb 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 一、线程池 实例: 1 import threadpool 2 import requests,time,threading 3 from hashlib import md5 4 def down_load_pic(url): 5 req = requests.get(url) 6 m = md5 阅读全文
posted @ 2019-11-30 21:55 xmb 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 一、异步任务 实例: 1 import yagmail,threading 2 def send_mail(): 3 smtp = yagmail.SMTP(host='smtp.163.com',user='xmb@163.com', 4 password='fsdfsf') 5 smtp.sen 阅读全文
posted @ 2019-11-30 21:48 xmb 阅读(853) 评论(0) 推荐(0) 编辑
摘要: 一、多线程下载文件 1 import requests,time,threading 2 from hashlib import md5 3 result = {} 4 def down_load_pic(url): 5 req = requests.get(url) 6 m = md5(url.e 阅读全文
posted @ 2019-11-30 21:40 xmb 阅读(1245) 评论(0) 推荐(0) 编辑
摘要: 一、多线程 1、多进程是多个资源的集合 2、线程是在进程里面干活 3、线程和线程之间是互相独立的 #实例 def down_load(): time.sleep(5) print('运行完了') def movie(): time.sleep(1) print('movie') start_time 阅读全文
posted @ 2019-11-30 21:38 xmb 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 一、发送请求类 import requests class MyRequest: def __init__(self,url,method='get',data=None,headers=None,is_json=False): method = method.lower() self.url = 阅读全文
posted @ 2019-11-30 18:58 xmb 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 一、操作数据库类 import pymysql class Db: def __init__(self,host,user,password,db,port=3306,charset='utf8'): #构造函数,实例化的时候自动执行构造函数 self.db_info = {'user': user 阅读全文
posted @ 2019-11-30 18:55 xmb 阅读(761) 评论(0) 推荐(0) 编辑
摘要: 一、面向对象 1、面向对象简介: 类(Class): 用来描述具有相同的属性和方法的对象的集合。它定义了该集合中每个对象所共有的属性和方法。对象是类的实例。 类变量:类变量在整个实例化的对象中是公用的。类变量定义在类中且在函数体之外。类变量通常不作为实例变量使用。 数据成员:类变量或者实例变量, 用 阅读全文
posted @ 2019-11-30 18:47 xmb 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 异常处理 1 a = [1,2,3] 2 d = {} 3 #例子1: 4 #判断key异常 5 try: 6 d['name'] 7 except KeyError as e: 8 print("字典key不存在",e) 9 else: 10 print('正常运行') 11 finally: 1 阅读全文
posted @ 2019-11-30 17:50 xmb 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 模拟登录、支付接口 1 import flask,json 2 import tools 3 4 server = flask.Flask(__name__) 5 #登录接口 6 @server.route('/login') 7 def login(): 8 username = flask.re 阅读全文
posted @ 2019-11-30 00:26 xmb 阅读(362) 评论(0) 推荐(0) 编辑
摘要: tools 1 import pymysql,hashlib,redis,time 2 3 #操作数据库 4 def op_mysql(sql,many=True): 5 db_info = {'user': 'xmb', 'password': '123456', 'host': '127.0.0 阅读全文
posted @ 2019-11-30 00:24 xmb 阅读(234) 评论(0) 推荐(0) 编辑