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("所有线程已完成")
2024-07-26
pyhton
00

背景:想要在两个不同的服务器之间进行数据传输,尝试了nc和scp命令,都没反应,经过不断地摸索,发现通过python创建一个服务,从而实现通过wget 命令实现文件的传输

  • 首先一定要使用python2相关的版本
  • python服务的开启执行命令为 python -m SimpleHTTPServer {端口}
  • 使用case
    • 在要传输的文件在/home/map/test目录下
    • 则在此目录下输入上述命令,开启一个服务, 设置端口为一个未使用的端口8877
    • 在目前机器下进行文件拉取
    sh
    wget 目标ip:8877/待拉取的文件.txt
2024-07-25
pyhton
00

问题背景

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" } ] }
  1. 需要下载python Debugger插件

ae8e1008ff19b912b9cc1c7afe3c836e.png