search_url_get_msg.py

 

 

复制代码
#!/usr/bin/env python3
import os
import logging
import glob
import sys
import re
from logging.handlers import RotatingFileHandler
from multiprocessing import Process
from multiprocessing import cpu_count
import multiprocessing
def search_url_message(i,url,path,result):
    logger.info("child_process {} cmd grep... ".format(i))
    comand = 'grep "{}" {}'.format(url,path)
    result_cmd = os.popen(comand)
    res = result_cmd.read()
    #print(comand)
    if res:
        result["0"] = res
def start_process(url):
    process_list = []
    result = multiprocessing.Manager().dict()
    path = '/var/log/yisa_get_msg_from_jd_kafka_process.log*'
    paths_list = []
    for i in range(321):
        if i != 0:
            paths_list.append('/var/log/yisa_get_msg_from_jd_kafka_process.log' + '.' +str(321-i))
        else:
            paths_list.append('/var/log/yisa_get_msg_from_jd_kafka_process.log')
    #for p in glob.glob(path):
    for p in paths_list:
        if '0' in result.keys():
            print(result["0"])
            break
            #sys.exit(0)
        if len(process_list) == cpu_count():
            while True:
                flag = 0
                for pro in process_list:
                    if not pro.is_alive():
                        process_list.remove(pro)
                        flag = 1
                if flag == 1:
                    break
        Pro = Process(target=search_url_message,args=(i,url,p,result))
        logger.info("child_process {} started... ".format(i))
        Pro.start()
        process_list.append(Pro)
        i = i + 1
        #if i == 60:
        #    break
    for p in process_list:
         p.kill()
if __name__ == '__main__':
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    handler = RotatingFileHandler(os.path.dirname(os.path.abspath(__file__)) + "/dl_images.log")
    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    if len(sys.argv) == 2:
        url = sys.argv[1]
        start_process(url)
    else:
        print("Unknown command")
复制代码

 

posted @   苦逼yw  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示