当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Importing salt causes flask to output nothing in the terminal

问题描述:

Suppose I have the following foo.py file:

#import salt

from flask import Flask

app = Flask(__name__)

@app.route('/')

def slash():

return 'foo'

if __name__ == '__main__':

app.run(debug=True)

If I run python foo.py I get this output and everything is fine:

 * Running on http://127.0.0.1:5000/

* Restarting with reloader

Now if I un-comment the import salt line and run python foo.py I get nothing in the terminal, although I can confirm with curl that my web app is indeed running. Is there any conflict between Salt Stack API and Flask, or have I perhaps discovered a bug?

I'm using Flask 0.10.1 and Salt 2014.7.0 with Python 2.7.6 inside a virtualenv.

EDIT: I found out what this is about, though I'm still not sure what the solution is. Salt calls logging.setLoggerClass(SaltLoggingClass) as part of its initialization and so SaltLoggingClass is used from then on as our logging class, even in other modules.

网友答案:

Okay I found out what is going on here and I also found a workaround. As I said on my last edit, this is Salt's doing as already reported here. The workaround is to initialize logging yourself before importing Salt. Something like this:

import sys
import logging
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format="%(message)s")

# Now we can import salt.
import salt

I don't think this is the best decision on Salt's part, but we have to do with what we got!

分享给朋友:
您可能感兴趣的文章:
随机阅读: