squeaky-pl / japronto

Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.
MIT License
8.61k stars 581 forks source link

Is there a way I can execute certain code upon webserver start? #110

Closed fourjr closed 6 years ago

fourjr commented 6 years ago

Title ^^

imgurbot12 commented 6 years ago

@fourjr You can wrap the application to execute code on startup.

Here is an example:

` from japronto import Application

class App(Application):

def run(self, *args, **kwargs):
    print("Code has been executed")
    Application.run(self, *args, **kwargs)

def hello(request): return request.Response(text='Hello world!')

app = App() app.router.add_route('/', hello) app.run(debug=True) `

Hope that helps!

fourjr commented 6 years ago

Oh ok thanks!