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?

dnsko
  • 1,017
  • 4
  • 17
  • 29
  • 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](http://stackoverflow.com/questions/1603109/how-to-make-a-python-script-run-like-a-service-or-daemon-in-linux). – redoc May 02 '16 at 08: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 – dnsko May 02 '16 at 08:19

1 Answers1

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.

dnsko
  • 1,017
  • 4
  • 17
  • 29