I have a flask app where I am reusing a function in a python script (poll_servers.py). I can import the function and run it but I want to put a check in place that exits the function if it's running.
Here is my code in the python script:
import os
import sys
# check if lock file exists, exit
if os.path.exists('static/poll.lock'):
sys.exit(1)
if not os.path.exists('static/poll.lock'):
with open('static/poll.lock', 'w'): pass
In my app.py I have:
from poll_servers import poll
@app.route('/poll_servers', methods=['GET'])
def poll_servers():
response = json.dumps({'status':'OK'})
poll()
return response
I get an error on the sys.exit(1)
in poll_servers.py:
File "app.py", line 109, in poll_servers
poll()
File ".../poll_servers.py", line 262, in poll
sys.exit(1)
File ".../venv/lib/python2.7/site.py", line 403, in __call__
raise SystemExit(code)
SystemExit: None
Any ideas? If I run the poll_servers.py on its own the sys.exit(1)
works fine.