if __name__=='__main__':
print("================================================= \n")
print 'The test will be running for: 18 hours ...'
get_current_time = datetime.now()
test_ended_time = get_current_time + timedelta(hours=18)
print 'Current time is:', get_current_time.time(), 'Your test will be ended at:', test_ended_time.time()
autodb = autodb_connect()
db = bw_dj_connect()
started_date, full_path, ips = main()
pid = os.getpid()
print('Main Process is started and PID is: ' + str(pid))
start_time = time.time()
process_list = []
for ip in ips:
p = Process(target=worker, args=(ip, started_date, full_path))
p.start()
p.join()
child_pid = str(p.pid)
print('PID is:' + child_pid)
process_list.append(child_pid)
child = multiprocessing.active_children()
print process_list
while child != []:
time.sleep(1)
child = multiprocessing.active_children()
print ' All processes are completed successfully ...'
print '_____________________________________'
print(' All processes took {} second!'.format(time.time()-start_time))
我有一个python测试脚本,应该运行18个小时,然后自杀。该脚本对多个设备使用多处理。我从main()函数获取的数据将随时间而改变。你知道吗
我将这三个参数传递给多重处理中的worker方法。你知道吗
我怎样才能做到这一点?你知道吗
如果您不需要担心子进程的清理太多,您可以使用
.terminate()
杀死它们如果您确实需要在所有子进程中进行一些清理,那么您需要修改它们的run循环(我假设
while True
),以监视时间的流逝,并且在主程序中只使用上面的第二个while循环,等待子进程自己离开。你知道吗你从不比较日期时间.now()测试时间。你知道吗
相关问题 更多 >
编程相关推荐