4

I'm trying to run something after the Flask server has started. The only thing I found is to run another thread with sleep. How can I do this?

this is not a duplicate because i need the server to listen when the method i want to run, executes.

i want to notify the server that sends requests to my server that my server is listening. the problem is that the other server checks if my service is up.

wa11a
  • 183
  • 1
  • 7

1 Answers1

-2

Use the before_first_request decorator. It will run this function before the first request is received. Here's an example

@app.before_first_request
def startup():
    conn.execute("CREATE TABLE IF NOT EXISTS users...")
    conn.commit()
    print("database tables created")
Jake Conway
  • 901
  • 16
  • 25
  • 7
    thanks but it doesn't help me because i wont get any request if i wont notify another service that the server is up. and the other service sends a get request to check if the server is up and listening. – wa11a Nov 17 '16 at 14:17