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()
评论列表
文章目录