Django manage.py 命令挂起

Django manage.py command hangs

以前正常工作的东西,刚刚放弃了我。当使用如下任何类型的 manage.py 命令时,我看到 Performing system checks...

python manage.py runserver 

python manage.py makemigrations

挂起大约 30-60 秒后,我得到:

System check identified no issues (0 silenced).

挂啊挂啊挂啊……大约6分钟后,我又看到正常了Quit the server with CONTROL-C 为了调试这个问题,我什至尝试注释掉我的应用程序和中间件,以及关闭我的 PY 上的其他应用程序并执行重启,仍然没有任何变化。我还需要看什么?这似乎太长了。

settings.py

import os
import logging

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SITE_ROOT = os.path.realpath(os.path.dirname(os.path.abspath(__file__)))
print ("SITE_ROOT: {0}".format(SITE_ROOT))
print ("BASE_DIR: {0}".format(BASE_DIR))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'blah'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'user_auth',
    #'users',
]

#Handle session is not Json Serializable
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

#Parameters for setting the expiry
SESSION_SAVE_EVERY_REQUEST = True
SESSION_EXPIRE_AT_BROWSER_CLOSE  = True
SESSION_COOKIE_AGE = 10

LDAP_SERVER = '10.253.8.31'
LDAP_AUTH_SEARCH_BASE = "ou=Konzern, dc=compnayx, dc=de"  # The LDAP search base for looking up users.
DOMAIN_NAME = 'MyDomain'


AUTHENTICATION_BACKENDS = (  
    'django.contrib.auth.backends.ModelBackend',
)

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    #'UserAuth.Middleware.ldap_interface.LDAP_Auth_Backend',
]

# Auto logout delay in minutes
AUTO_LOGOUT_DELAY = 1 #equivalent to 1 minutes

ROOT_URLCONF = 'UserAuth.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'UserAuth.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'

USE_I18N = True
USE_L10N = True
USE_TZ = False # Does not assume timestamps in DB are all in UTC


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'

ADMINS = (
  ('me', 'myemail'),
)
MAILER_LIST = ['myemail']          # To whom shall the mail be sent
EMAIL_HOST = 'smtp-mail.outlook.com'   
EMAIL_HOST_USER = 'another_email'   # We're sending the notification from here so we need HOST, PW, PORT
EMAIL_HOST_PASSWORD = 'my_password'
EMAIL_PORT = 25
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'myemail'

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
        },
    },
    'handlers': {
        'default': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': SITE_ROOT + '\logfile.log',
            'maxBytes': 1024*1024*5, # 5 MB
            'backupCount': 5,
            'formatter':'standard',
        },  
        'request_handler': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename':  SITE_ROOT + '\django_request.log',
            'maxBytes': 1024*1024*5, # 5 MB
            'backupCount': 5,
            'formatter':'standard',
        },
        'mail_admins': {
            'level': 'DEBUG',
            'class': 'django.utils.log.AdminEmailHandler',
    },
 },
    'loggers': {
        '': {
                'handlers': ['mail_admins', 'default'],
                'level': 'DEBUG',
                'propagate': True
        },
        'django.request': {
                'handlers': ['request_handler'],
                'level': 'DEBUG',
                'propagate': False
        },
        'django': {
                'handlers': ['request_handler', 'default', 'mail_admins'],
                'level': 'DEBUG',
                'propagate': True,
        },
    }
}

我自己找到了问题所在。它与我的 settings.py 文件有关:

ADMINS = (
  ('My name', 'myemail@domain.com'),
)

注释掉此代码使 manage.py 命令的速度再次恢复正常。我不太确定为什么除了通知尝试 send/communicate 使用此地址之外的原因,并且由于我在代理后面,所以该过程花费了几分钟的时间。也许有人可以为此提供更准确的原因。