我有這個簡單的瓶應用:瓶和Web.py都掛在atexit對
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)
的prolog_handler模塊與triplestore並加載一些規則啓動一個會話。它還有一個atexit函數,可以結束會話並打印一條消息,如「正在關閉...」。我使用python myapp.py
從bash提示符啓動服務器。每當我按CTRL-C停止服務器時,什麼都不會發生。我不會返回到bash提示符,並且我看不到「正在打印...」消息。我也試圖用Web.py來做到這一點,並得到相同的結果。
tstore = openPrologSession()
rules = ...
def cleanUp():
print "Closing..."
tstore.endSession()
atexit.register(cleanUp)
那麼,爲什麼這麼難,只是執行的atexit任務:
的那prolog_handler確實是字面上這麼簡單? PS:如果我註釋掉所有關於打開Prolog Session並結束它的內容,並且只留下打印消息「Closing ...」的部分,那麼當我看到「Closing ...」消息時我打CTRL-C,我確實返回到bash提示符。這按預期工作。但是如果我不能對它做任何有用的事情,那又有什麼意義呢?
啊哈!酷男,謝謝! –
@John Peter ThompsonGarcés:謝謝。檢查這是否適合你。 – pyfunc
是的,它按預期工作! –