Django channels 채팅 서버 구축 튜토리얼 도중에 난 에러
[Python/Django] - [Django Channels] Building simple Chat Server / 채팅 서버 구현 튜토리얼 part.1
에러 내용
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Python\Python38-32\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\django\core\management\commands\runserver.py", line
109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\django\apps\config.py", line 116, in create
mod = import_module(mod_path)
File "C:\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\channels\apps.py", line 6, in
import daphne.server
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\daphne\server.py", line 20, in
asyncioreactor.install(twisted_loop)
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\twisted\internet\asyncioreactor.py", line 320, in install
reactor = AsyncioSelectorReactor(eventloop)
nit__
super().__init__()
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\twisted\internet\base.py", line 571, in __init__
self.installWaker()
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\twisted\internet\posixbase.py", line 286, in installWaker
self.addReader(self.waker)
File "C:\Users\jisun\dev\python\django\chat_tutorial\myvenv\lib\site-packages\twisted\internet\asyncioreactor.py", line 151, in addReader
self._asyncioEventloop.add_reader(fd, callWithLogger, reader,
File "C:\Python\Python38-32\lib\asyncio\events.py", line 501, in add_reader
raise NotImplementedError
NotImplementedError
해결 방법
내 환경은 windows10, python 3.8.1 인데,
windows환경과 python 3.8 버전의 콜라보(?)로 문제가 된 것 같은데
이를 고치려면
1. python 3.7 버전으로 rollback하거나,
2. 코드를 살짝 수정해서 win32일 경우 어쩌구저쩌구 하면 된다.
나는 비교적 간단한 2번 방법을 사용했다!
Django project의 __init__.py에 다음 코드를 붙여넣기만 하면된다!
import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
https://github.com/django/channels/issues/969