![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python技术栈
小小码头,大大秃头
前人栽树,后人乘凉。
展开
-
日志装饰器几种简单实现
日志装饰器def say_hello(country): def wrapper(func): def deco(*args, **kwargs): if country == 'china': print('你好!') elif country == 'america': print('hello') else:原创 2021-07-18 17:04:28 · 109 阅读 · 0 评论 -
心跳监控的基础逻辑
心跳监控的基础逻辑import threadingfrom time import sleepclass Heartbeat(threading.Thread): # 重点:要继承多线程父类,才能开启线程来做循环,不阻塞主线程 def __init__(self,): super(Heartbeat,self).__init__() def run(self): while True: print("333",threading原创 2021-07-18 16:59:44 · 168 阅读 · 0 评论 -
两个文件读取比较内容的几种方式
两个文件读取比较内容的几种方式import csvfrom decimal import Decimal# with open('ctp.csv', 'r') as f:# reader = csv.reader(f)# ctp_list = list(reader)# print(ctp_list[1])## with open('rem.csv', 'r') as f:# reader = csv.reader(f)# rem_list =原创 2021-07-18 16:53:22 · 133 阅读 · 0 评论 -
函数调用继承了threading类的函数,不需要阻塞主线程,猜测默认等待子线程。
函数调用继承了threading类的函数,不需要阻塞主线程,猜测默认等待子线程。import threadingfrom time import sleepclass Heartbeat(threading.Thread): def __init__(self,): super(Heartbeat,self).__init__() def run(self): while True: print("333",threadi原创 2021-06-20 17:09:22 · 115 阅读 · 0 评论 -
记录GIL导致多线程变单线程
最近在看Python的多线程,经常我们会听到老手说:“python下多线程是鸡肋,推荐使用多进程!”,但是为什么这么说呢?要知其然,更要知其所以然。所以有了下面的深入研究:首先强调背景:1、GIL是什么?GIL的全称是Global Interpreter Lock(全局解释器锁),来源是python设计之初的考虑,为了数据安全所做的决定。2、每个CPU在同一时间只能执行一个线程(在单核CPU下的多线程其实都只是并发,不是并行,并发和并行从宏观上来讲都是同时处理多路请求的概念。但并发和并行又有区别,并翻译 2021-06-16 12:09:24 · 240 阅读 · 0 评论