asyncio issue in Apache deployment

Hi,
First of all I’m still a newbie so please forgive me for silly questions.

I tried to deploy my first project to Apache but I the following errors appears frequently which makes my project throws Server Error (500) which is really weird because I never saw this error in my local machine (Linux Mint) but appears in Windows server!

NOTE: Server Error (500) doesn’t always appear but most of the time it does.

[Tue Jul 07 11:42:51.147492 2020] [wsgi:error] [pid 6508:tid 1084]   app_config.ready()\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842] Exception ignored in: <function BaseEventLoop.__del__ at 0x000000BC070CE550>\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842] Traceback (most recent call last):\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]   File "c:\\python38\\lib\\asyncio\\base_events.py", line 656, in __del__\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]     self.close()\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]   File "c:\\python38\\lib\\asyncio\\proactor_events.py", line 679, in close\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]     signal.set_wakeup_fd(-1)\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842] ValueError: set_wakeup_fd only works in main thread\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842] Exception ignored in: <function BaseEventLoop.__del__ at 0x000000BC070CE550>\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842] Traceback (most recent call last):\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]   File "c:\\python38\\lib\\asyncio\\base_events.py", line 656, in __del__\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]     self.close()\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]   File "c:\\python38\\lib\\asyncio\\proactor_events.py", line 679, in close\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]     signal.set_wakeup_fd(-1)\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842] ValueError: set_wakeup_fd only works in main thread\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842] Exception ignored in: <function BaseEventLoop.__del__ at 0x000000BC070CE550>\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842] Traceback (most recent call last):\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]   File "c:\\python38\\lib\\asyncio\\base_events.py", line 656, in __del__\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]     self.close()\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]   File "c:\\python38\\lib\\asyncio\\proactor_events.py", line 679, in close\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842]     signal.set_wakeup_fd(-1)\r
[Tue Jul 07 11:42:51.788082 2020] [wsgi:error] [pid 6508:tid 1084] [client 78.180.215.26:53842] ValueError: set_wakeup_fd only works in main thread\r

httpd.conf added these lines at the end

LoadFile "c:/python38/python38.dll"
LoadModule wsgi_module "c:/python38/lib/site-packages/mod_wsgi/server/mod_wsgi.cp38-win_amd64.pyd"
WSGIPythonHome "c:/python38"

httpd-vhosts.conf

Define CERTROOT "C:/apache-certs"
Define SITEROOT "${SRVROOT}/htdocs"
Define DJANGOSITEROOT "C:/django-project"

<VirtualHost *:443>
    DocumentRoot "${SITEROOT}"
    ServerAdmin admin@mydomain.com
    ServerName mydomain.com
	ServerAlias www.mydomain.com
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^mydomain.com$ [NC]
    RewriteRule ^/?(.*)$ https://mydomain.com/$1 [NE,L,R=301]
    Alias /.well-known ${SITEROOT}/.well-known
    SSLEngine on
    SSLCertificateFile "${CERTROOT}/mydomain.com-crt.pem"
    SSLCertificateKeyFile "${CERTROOT}/mydomain.com-key.pem"
    SSLCertificateChainFile "${CERTROOT}/mydomain.com-chain.pem"
	
	WSGIPassAuthorization On
    WSGIScriptAlias /api  "${DJANGOSITEROOT}/site_bot/wsgi_windows.py"
	<Directory "${DJANGOSITEROOT}/site_bot">
        <Files wsgi_windows.py>
            Require all granted
        </Files>
    </Directory>
	Alias /static "${DJANGOSITEROOT}/static"
	<Directory "${DJANGOSITEROOT}/static">
		Require all granted
	</Directory>
</VirtualHost>

wsgi_windows.py

import os
import sys
from django.core.wsgi import get_wsgi_application

sys.path.append('C:/django-project')
sys.path.append('C:/django-project/site_bot')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'site_bot.settings')
application = get_wsgi_application()

settings.py

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'django_telegrambot',
    'api',
]
  • Windows Server 2012 R2 Standard
  • Apache 2.4.41
  • Python 3.8.3
  • PIP list:
asgiref==3.2.10
astroid==2.4.2
certifi==2020.6.20
cffi==1.14.0
colorama==0.4.3
cryptography==2.9.2
decorator==4.4.2
Django==3.0.7
django-templated-mail==1.1.1
djangorestframework==3.11.0
djoser==2.0.3
isort==4.3.21
lazy-object-proxy==1.4.3
mccabe==0.6.1
mod-wsgi==4.7.1
pycparser==2.20
pylint==2.5.3
python-telegram-bot==12.8
pytz==2020.1
six==1.15.0
sqlparse==0.3.1
toml==0.10.1
tornado==6.0.4
wfastcgi==3.0.0
wrapt==1.12.1 

Just as a real wild off-the-cuff WAG on this, it appears you’re trying to perform an async function within Apache’s wsgi (sync) container?

I would be surprised to see it work reliably.

Do you mean I can’t run async under Apache? If yes; Does this problem apply only for Apache/Windows or for Apache in general?

It seems this is semi-know bug!

1 Like