pythondef 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
Python的线程更适合处理I/O密集型任务(如网络请求、文件读写),因为GIL不会阻碍I/O操作的并发。
pythonimport 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("所有线程已完成")
python -m SimpleHTTPServer {端口}
shwget 目标ip:8877/待拉取的文件.txt
问题背景
python项目debug起不来
解决方案: 1.设置launch.json
python{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "load_app",
"type": "debugpy",
"request": "launch",
"program": "项目路径/server/server.py",
"console": "integratedTerminal"
}
]
}