zmapd.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:webzmap 作者: fengyouchao 项目源码 文件源码
def start():
    if os.path.exists(settings.pid_file):
        with open(settings.pid_file) as f:
            try:
                fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
                fcntl.flock(f, fcntl.LOCK_UN)
            except IOError:
                sys.stdout.write("zmapd is already started\n")
                return

    run_daemon_process(pid_file=settings.pid_file, start_msg="Start zmapd(%s)\n")
    pid_file = open(settings.pid_file)
    fcntl.flock(pid_file, fcntl.LOCK_SH)
    while True:
        time.sleep(1)
        running_jobs = Job.objects.filter(status=Job.STATUS_RUNNING)
        total_bandwidth = 0
        for job in running_jobs:
            total_bandwidth += job.bandwidth
        if total_bandwidth >= settings.max_bandwidth:
            logger.debug(u"Achieve maximum bandwidth:%sM", settings.max_bandwidth)
            continue
        jobs = [x for x in Job.objects.filter(status=Job.STATUS_PENDING).order_by('-priority')]
        db.close_old_connections()
        for j in jobs:
            p = multiprocessing.Process(target=execute_job, args=(j.id,))
            p.start()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号