如何避免apscheduler向子进程添加作业?

时间:2014-08-26 08:46:49

标签: python apscheduler

我hava在我的进程中添加了一个apscheduler作业,我发现我的子进程也有这个工作, 我的主要流程和子流程同时执行这项工作......

主程序是

server = StreamServer((server_ip, server_port), serve_forever, spawn = pool, backlog=100000)

for i in range(process_count - 1):
    Process(target=serve_forever, args=()).start()

我的导师是

   scheduler =BackgroundScheduler()
    scheduler.add_job(tick, 'interval', seconds=3)
    scheduler.start()

输出

Tick! The time is: 1409042763.26 pocess is 11428
Tick! The time is: 1409042763.26 pocess is 11431
Tick! The time is: 1409042763.26 pocess is 11424
Tick! The time is: 1409042763.26 pocess is 11430
Tick! The time is: 1409042763.26 pocess is 11426
Tick! The time is: 1409042763.26 pocess is 11380
Tick! The time is: 1409042763.26 pocess is 11425
Tick! The time is: 1409042763.26 pocess is 11429
Tick! The time is: 1409042763.26 pocess is 11432
Tick! The time is: 1409042763.26 pocess is 11433

1 个答案:

答案 0 :(得分:0)

一些想法:

  1. 只有在您创建了子流程
  2. 后才启动调度程序
  3. 关闭子流程中的调度程序
  4. 通过除分支主进程之外的其他方式创建子进程