I have this simple Flask app:
from flask import Flask
import prolog_handler as p
app = Flask(__name__)
app.debug = False
@app.route('/')
def hello():
for rule in p.rules:
print rule
return 'hello'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
The prolog_handler module starts a session with a triplestore and loads some rules. It also has an atexit function that ends the session and prints a message like "Closing...". I start the server from the bash prompt with python myapp.py
. Whenever I hit CTRL-C to stop the server, nothing happens. I don't get returned back to the bash prompt, and I don't see the "Closing..." message printed. I also tried to do this with Web.py with the same results.
The that prolog_handler does is literally as simple as this:
tstore = openPrologSession()
rules = ...
def cleanUp():
print "Closing..."
tstore.endSession()
atexit.register(cleanUp)
So why is it so difficult to just perform an atexit task?
PS: if I comment out all the stuff about opening the Prolog Session and ending it, and just leave the part that prints the message "Closing..." then I do see the "Closing..." message when I hit CTRL-C and I do get returned to the bash prompt. That works as expected. But what's the point of atexit if I can't do anything useful with it?