0

I currently have a process running that should call a method every 10 seconds. I see that it actually calls the method at that interval, but it seems to not execute something in the code. Weird thing is, is that when I cancel the loop, and start it new it does actually do it the first time. Then when I keep it running it does not do anything.

def main():
    try:
        while True:
            read()
            time.sleep(10)
    except KeyboardInterrupt:
        pass

Above is the loop, and the code here is actually the beginning of the method that is being called, and I found out that it does not actually get results in the results, while the file has changed. In this case it gets data from a .json file

def read():
    message = Query()
    results = DB.search(message.pushed == False)

Am I overlooking something?

2
  • How are you sure that read() is being called after KeyboardInterrupt ? Ideally your program will exit upon KeyboardInterrupt(Ctrl+C). Try to put a print statement in read() and check if you see that statement on console. If you wan to run this continuously, you have to run it as a daemon process. Commented May 2, 2016 at 8:10
  • I had indeed put a print statement there, so I know it's being called. The file is being run as a service on the server, it keeps calling the method every 10 seconds. It seems to run fine, it's just that it does not get any results from the database Commented May 2, 2016 at 8:19

1 Answer 1

1

Solved. I had the DB declared globally and that did not go so well. It is being fixed by declaring it just before the statement.

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.