=== Steps to reproduce
1. Open any Django project.
2. Run `python manage.py runserver`.
==== Actual result
{{{
C:\Programs\Python38\python.exe C:/project/manage.py runserver
2020-10-11 18:12:08,823 INFO [django.utils.autoreload] Watching for file
changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Programs\Python38\lib\threading.py", line 932, in
_bootstrap_inner
self.run()
File "C:\Programs\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Programs\Python38\lib\site-
packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Programs\Python38\lib\site-
packages\django\core\management\commands\runserver.py", line 110, in
inner_run
autoreload.raise_last_exception()
File "C:\Programs\Python38\lib\site-
packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Programs\Python38\lib\site-
packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Programs\Python38\lib\site-
packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Programs\Python38\lib\site-packages\django\__init__.py", line
24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Programs\Python38\lib\site-packages\django\apps\registry.py",
line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Programs\Python38\lib\site-packages\django\apps\config.py",
line 116, in create
mod = import_module(mod_path)
File "C:\Programs\Python38\lib\importlib\__init__.py", line 127, in
import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in
_find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in
_call_with_frames_removed
File "C:\Programs\Python38\lib\site-packages\channels\apps.py", line 6,
in <module>
import daphne.server
File "C:\Programs\Python38\lib\site-packages\daphne\server.py", line 20,
in <module>
asyncioreactor.install(twisted_loop)
File "C:\Programs\Python38\lib\site-
packages\twisted\internet\asyncioreactor.py", line 320, in install
reactor = AsyncioSelectorReactor(eventloop)
File "C:\Programs\Python38\lib\site-
packages\twisted\internet\asyncioreactor.py", line 69, in __init__
super().__init__()
File "C:\Programs\Python38\lib\site-packages\twisted\internet\base.py",
line 571, in __init__
self.installWaker()
File "C:\Programs\Python38\lib\site-
packages\twisted\internet\posixbase.py", line 286, in installWaker
self.addReader(self.waker)
File "C:\Programs\Python38\lib\site-
packages\twisted\internet\asyncioreactor.py", line 151, in addReader
self._asyncioEventloop.add_reader(fd, callWithLogger, reader,
File "C:\Programs\Python38\lib\asyncio\events.py", line 501, in
add_reader
raise NotImplementedError
NotImplementedError
}}}
==== Expected result
No errors.
=== Workaround
Add the following code to the `manage.py` file:
{{{
#!python
if sys.platform == 'win32' and sys.version_info >= (3, 8):
import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
}}}
=== References
- https://stackoverflow.com/questions/58908293/i-keep-getting-
notimplementederror-error-when-starting-django-server
--
Ticket URL: <https://code.djangoproject.com/ticket/32103>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
* severity: Release blocker => Normal
Comment:
This is not an issue in Django but in `twisted`. Please report it in their
bug tracker.
--
Ticket URL: <https://code.djangoproject.com/ticket/32103#comment:1>
Comment (by Andrey Zelenchuk):
> Windows on Python 3.8+ uses ProactorEventLoop
This is not accurate. Python 3.8+ on Windows uses the
[https://docs.python.org/3/library/asyncio-
eventloop.html#asyncio.ProactorEventLoop ProactorEventLoop] **by
default**. Python 3.8+ on Windows allows to use the
[https://docs.python.org/3/library/asyncio-
eventloop.html#asyncio.SelectorEventLoop SelectorEventLoop] as well.
> <...> which is not compatible with Twisted
So why then Django tries to use the ProactorEventLoop with Twisted?
> Recent versions of Daphne automatically set the correct event loop
policy in these cases.
Django's `runserver` management command does not use Daphne, does it? Why
Django cannot set the correct event loop policy too?
This ticket is not invalid until the Django's documentation states that
Django does not support Python 3.8+ on Windows. Besides, it looks like it
can be fixed quite easily. So, could you reopen it, please?
--
Ticket URL: <https://code.djangoproject.com/ticket/32103#comment:3>
Comment (by Andrey Zelenchuk):
> Your stack trace says you're using channels, which does use
Daphne/twisted yes.
Yes, that's right, thank you! Sorry, I missed that Channels replaces the
Django's `runserver` management command. This bug is invalid for Django,
and it is already fixed in the recent version of Channels/Daphne/Twisted.
--
Ticket URL: <https://code.djangoproject.com/ticket/32103#comment:6>