2024-08-09
linux相关
00

学习背景

很多linux相关的知识都不太了解,所以需要不断地补充自己的知识储备

2024-08-06
linux相关
00

linux查看内存占用命令

sh
ps aux --sort=-%mem |head

或者top 然后按下 Shift + M 键(注意大写),按照内存使用量排序进程。

sh
top
2024-08-02
pyhton
00

背景:有时候需要校验文件内容是否拉取完成,可以通过md5加密进行判断

通过python的加密实现

python
def cal_file_md5(file_path): ''' 计算渠道包(未签名)md5 :param file_path: :return: ''' try: # with open(file_path, 'rb') as fp: # data = fp.read() # file_md5 = hashlib.md5(data).hexdigest() # return file_md5 m = hashlib.md5() with open(file_path, 'rb') as fp: while True: # 分块读取,一次20M(20*1024*1024) data = fp.read(20971520) if not data: break m.update(data) file_md5 = m.hexdigest() return file_md5 except Exception as e: r_logger.loginfo('[渠道包md5计算错误]:' + file_path + str(e)) r_alert.alert_admin('[渠道包md5计算错误]:' + file_path + str(e)) return False
2024-07-31
linux相关
00
2024-07-29
pyhton
00

Python的线程更适合处理I/O密集型任务(如网络请求、文件读写),因为GIL不会阻碍I/O操作的并发。

python
import threading # 定义要在每个线程中执行的任务 def worker(thread_id): print(f"线程 {thread_id} 正在执行任务") # 在这里添加实际的任务代码 # 模拟任务执行时间 import time time.sleep(1) print(f"线程 {thread_id} 完成任务") # 创建一个线程列表 threads = [] # 启动10个线程 for i in range(10): thread = threading.Thread(target=worker, args=(i,)) threads.append(thread) thread.start() # 等待所有线程完成 for thread in threads: thread.join() print("所有线程已完成")