Starting flask server in background

后端 未结 4 1676
感动是毒
感动是毒 2021-02-01 05:13

I have a flask application which I am currently starting up in the following way:

#phantom.py
__author__ = \'uruddarraju\'
from phantom.api.v1 import app
app.run         


        
4条回答
  •  旧巷少年郎
    2021-02-01 05:59

    Probably the best way to do this is behind nginx like @RaphDG answered, But if you want to run it in the background for personal use I found that the logging system would not let you to use only with "&" at the end of the command line, in addition i found that the logger is internal logger of Werkzeug library.

    To get around this you can do the next steps(code below):

    1. import werkzeug._internal
    2. create demi logger class
    3. Assign the new class to werkzeug._internal._log (log class)

    It will evade notifications and loggers and let you run this process in the background (with "&")

    code:

    import werkzeug._internal
    
    def demi_logger(type, message,*args,**kwargs):
        pass
    

    the first line in the __main__:

    werkzeug._internal._log = demi_logger
    

提交回复
热议问题