title: Not allowing me call python flask API while server still executing some function
body: <p>I am trying to implement flask client server architecture for the first time.</p>
  <p>My server code:</p>
  <pre><code>from flask import Flask, request
  from Flask.Config import Config
  
  global config
  
  class MyFlaskApp(Flask):
      def run(self, host=None, port=None, debug=None, load_dotenv=True, **options):
          if not self.debug or os.getenv('WERKZEUG_RUN_MAIN') == 'true':
              with self.app_context():
                  init()
          super(MyFlaskApp, self).run(host=host, port=port, debug=debug, load_dotenv=load_dotenv, **options)
  
  
  app = MyFlaskApp(__name__)
  
  
  def init():
      global config
      config = Config()
      config.configure()
      config.execute()
  
  
  @app.route('/get_results/', methods=['POST'])
  def process_request():
      global config
      dict = config.get_dictionary()
      json_object = json.dumps(dict)
      return json_object
  
  
  if __name__ == &quot;__main__&quot;:
      app.run(debug=True, port=5000)
  </code></pre>
  <p>I am performing some continuous executions (<code>while True:</code> loop) in <code>config.execute()</code> method in <code>init()</code> function., which updates some dictionary continuously. Client code calls the server API and gets updated dictionary. My client code:</p>
  <pre><code>import requests    
  
  def main():
      response = requests.post(&quot;http://127.0.0.1:5000/get_parking_results/&quot;).json()
  
  if __name__ == &quot;__main__&quot;:
      main()
  </code></pre>
  <p>I run server first, it does the intended computations and updates dictionary. But when I run client side code it gives me following error:</p>
  <pre><code>requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=5000): Max retries exceeded with url: /get_parking_results/ (Caused by NewConnectionError('&lt;urllib3.connection.HTTPConnection object at 0x0000020A922D4828&gt;: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))
  </code></pre>
  <p>However, If I comment <code>config.execute()</code> from <code>init()</code> function then it successfully returns the dictionary to client. Basically it is not allowing me to send request to server while server is continuously executing something in while loop. Why is this happening? I tried running <code>init()</code> function through a separate thread, it worked. What if I don't want to use thread? What is the solution?</p>