title: How to avoid AppConfig.ready() method running twice in Django
body: <p>I want to execute some code at startup of Django server but I want it to run only once. Currently when I start the server it's executed twice. <a href="https://docs.djangoproject.com/en/1.8/ref/applications/" rel="noreferrer">Documentation</a> says that this might happen and:</p>
  
  <blockquote>
    <p>you should put a flag on your AppConfig classes to prevent re-running
    code which should be executed exactly one time.</p>
  </blockquote>
  
  <p>Any idea how to achieve this? Print statement below is still executed twice.</p>
  
  <pre><code>from django.apps import AppConfig
  import app.mqtt
  from apscheduler.schedulers.background import BackgroundScheduler
  
  class MyAppConfig(AppConfig):
      name = 'app'
      verbose_name = "HomeIoT"
      run_already = False
  
      def ready(self):
          if MyAppConfig.run_already: return
          MyAppConfig.run_already = True
          print("Hello")
  </code></pre>