title: FastAPI restart server over and over again whenever a new webhook is received when calling a def function
body: <p>I created a simple fastapi server to receive webhook, and whenever there is a webhook signal, it call the function printmessage() to print out the message &quot;WEBHOOK RECEIVED&quot;. And the code appears to work, but whenever there is a new webhook, my server will restart again which is not what I intend to do and it seems that the problem comes from calling the function, it appears that whenever a function is called, it will run the main.py all over again (&quot;PROGRAM LAUNCH...&quot; is printed out when new webhooks received but it suppose only run once) instead running once only, but I just want the program to run the function print message()only instead running all the code all over again, how can I solve this issue?</p>
  <pre><code>#main.py
  import time
  from fastapi import Request, FastAPI
  
  def printmessage():
      print(&quot;WEBHOOK RECEIVED&quot;) 
  
  app = FastAPI()
  print(&quot;PROGRAM LAUNCH...&quot;)
  print(&quot;WEBHOOK RECEIVE READY...&quot;)
  @app.post(&quot;/webhook&quot;)
  async def webhook(request : Request):     
      printmessage()
      return 'WEBHOOK RECEIVED'       
    
  </code></pre>
  <p><strong>OUTPUT:</strong></p>
  <pre><code>INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
  INFO:     Started reloader process [984] using statreload
  WARNING:  The --reload flag should not be used in production on Windows.
  PROGRAM LAUNCH...
  WEBHOOK RECEIVE READY...
  INFO:     Started server process [13308]
  INFO:     Waiting for application startup.
  INFO:     Application startup complete.
  INFO:     127.0.0.1:49353 - &quot;POST /webhook HTTP/1.1&quot; 200 OK
  PROGRAM LAUNCH...
  WEBHOOK RECEIVE READY...
  WEBHOOK RECEIVED
  INFO:     127.0.0.1:49353 - &quot;POST /webhook HTTP/1.1&quot; 200 OK
  PROGRAM LAUNCH...
  WEBHOOK RECEIVE READY...
  WEBHOOK RECEIVED
  INFO:     127.0.0.1:49524 - &quot;POST /webhook HTTP/1.1&quot; 200 OK
  PROGRAM LAUNCH...
  WEBHOOK RECEIVE READY...
  WEBHOOK RECEIVED
  INFO:     127.0.0.1:49524 - &quot;POST /webhook HTTP/1.1&quot; 200 OK
  PROGRAM LAUNCH...
  WEBHOOK RECEIVE READY...
  WEBHOOK RECEIVED
  INFO:     127.0.0.1:49524 - &quot;POST /webhook HTTP/1.1&quot; 200 OK
  PROGRAM LAUNCH...
  WEBHOOK RECEIVE READY...
  WEBHOOK RECEIVED
  </code></pre>
  <p><strong>INTENDED OUTPUT:</strong></p>
  <pre><code>INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
  INFO:     Started reloader process [24368] using statreload
  WARNING:  The --reload flag should not be used in production on Windows.
  PROGRAM LAUNCH...
  WEBHOOK RECEIVE READY...
  INFO:     Started server process [38368]
  INFO:     Waiting for application startup.
  INFO:     Application startup complete.
  WEBHOOK RECEIVED
  INFO:     127.0.0.1:49675 - &quot;POST /webhook HTTP/1.1&quot; 200 OK
  WEBHOOK RECEIVED
  INFO:     127.0.0.1:49675 - &quot;POST /webhook HTTP/1.1&quot; 200 OK
  WEBHOOK RECEIVED
  INFO:     127.0.0.1:49675 - &quot;POST /webhook HTTP/1.1&quot; 200 OK
  WEBHOOK RECEIVED
  INFO:     127.0.0.1:49675 - &quot;POST /webhook HTTP/1.1&quot; 200 OK
  WEBHOOK RECEIVED
  INFO:     127.0.0.1:49675 - &quot;POST /webhook HTTP/1.1&quot; 200 OK
  </code></pre>