1

我已经在我的进程中添加了一个 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
4

1 回答 1

0

一些想法:

  1. 仅在创建子流程后启动调度程序
  2. 关闭子进程中的调度器
  3. 通过分叉主进程以外的其他方式创建子进程
于 2014-08-26T19:22:37.627 回答