0

I am using python daemon to check a particular table in mongodb if there is any value it should call another python script. Below is the code what I am trying, but it doesn't call the script. can somebody help me out:

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 Answer 1

1

yes i got it. Am posting as it may be it helps someone

Instead of using

os.system(path)

Use:

subprocess.call(['python', '/Path_from_root_directory/XYZ.py', ids]) // ids is my argument to be passed
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.