import os import sys from django.apps import AppConfig class QuizAppConfig(AppConfig): name = 'quiz' default_auto_field = 'django.db.models.BigAutoField' def ready(self): """ App initialization code. Starts the auto-import watcher in a background thread. """ # Only run in the main process (not in reloader process) # And not during management commands or pytest tests is_management_command = any(cmd in sys.argv for cmd in ['import_questions', 'migrate', 'makemigrations', 'shell']) is_pytest = 'pytest' in sys.argv[0] or 'PYTEST_CURRENT_TEST' in os.environ if not is_management_command and not is_pytest and (os.environ.get('RUN_MAIN') == 'true' or os.environ.get('RUN_MAIN') is None): from quiz.utils.watcher import start_watcher_thread start_watcher_thread()