2014-09-22 100 views
0

我正在使用python守護進程來檢查mongodb中的某個表,如果有任何值應該調用另一個python腳本。 下面是我正在嘗試的代碼,但它不會調用腳本。 有人可以幫助我:python守護進程沒有調用其他python腳本

import daemon 
import time 
import os 
from pymongo import MongoClient 


connection = MongoClient(IPADDRESS, PORT) 
monitor_db = connection.testmongo.XYZ_monitoring 

def interval_monitoring(): 
    while True: 
     searchForm = monitor_db.find() 
     for user in searchForm: 
      user_id=user['user_id'] 
      for ids in user_id: 
       path= "python XYZ.py "+ids 
       os.system(path) 
     time.sleep(60) 


def run(): 
    print daemon.__file__ 
    with daemon.DaemonContext(): 
     interval_monitoring() 

if __name__ == "__main__": 
    run() 

回答

1

是的,我明白了。上午發佈,因爲它可能是它可以幫助別人

而不是使用

os.system(path) 

用途:

subprocess.call(['python', '/Path_from_root_directory/XYZ.py', ids]) // ids is my argument to be passed