취미삼아 배우는 프로그래밍

오류해결 django channels twisted asyncioreactor Error 본문

파이썬(장고)

오류해결 django channels twisted asyncioreactor Error

Nadure 2019. 12. 31. 06:18

오류해결 django channels twisted asyncioreactor Error

오류환경 : Win10 32Bit

오류 내역은 다음과 유사하다.

(env) C:\Users\LENOVO\Desktop\SD\backend>python manage.py runserver
    Watching for file changes with StatReloader
    Exception in thread django-main-thread:
    Traceback (most recent call last):
      File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
        self.run()
      File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
        self._target(*self._args, **self._kwargs)
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
        fn(*args, **kwargs)
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
        autoreload.raise_last_exception()
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\django\utils\autoreload.py", line 77, in raise_last_exception
        raise _exception[1]
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\django\core\management\__init__.py", line 337, in execute
        autoreload.check_errors(django.setup)()
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
        fn(*args, **kwargs)


      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\django\__init__.py", line 24, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\django\apps\registry.py", line 91, in populate
        app_config = AppConfig.create(entry)
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\django\apps\config.py", line 116, in create
        mod = import_module(mod_path)
      File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\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:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\channels\apps.py", line 6, in <module>
        import daphne.server
File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\daphne\server.py", line 18, in <module>
        asyncioreactor.install()
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\twisted\internet\asyncioreactor.py", line 320, in install
        reactor = AsyncioSelectorReactor(eventloop)
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\twisted\internet\asyncioreactor.py", line 69, in __init__
        super().__init__()
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\twisted\internet\base.py", line 571, in __init__
        self.installWaker()
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\twisted\internet\posixbase.py", line 286, in installWaker
        self.addReader(self.waker)
      File "C:\Users\LENOVO\Desktop\SD\backend\env\lib\site-packages\twisted\internet\asyncioreactor.py", line 151, in addReader
        self._asyncioEventloop.add_reader(fd, callWithLogger, reader,
      File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\lib\asyncio\events.py", line 501, in add_reader
        raise NotImplementedError
    NotImplementedError

>> Python manage.py makemigrations 안됨

>> Python manage.py migrate 안됨

>> Python manage.py migrate --run-syncdb 안됨

 

아마도

Django Channels 2.4.0 버전을 32bit에서 사용시 에러가 발생하는것 같다.

집에서 만든 소스를 회사서 켜보려 하니 죽도록 안되더라.

어찌어찌 하다보니 해결법을 찾았다.

 

 

 

스택오버플로우를 통해 \env\lib\site-packages\twisted\internet\asyncioreactor.py 를 직접 수정함으로써 오류를 수정하였다.

from twisted.internet.interfaces import IReactorFDSet

try:
    from asyncio import get_event_loop
except ImportError:
    raise ImportError("Requires asyncio.")

# As per ImportError above, this module is never imported on python 2, but

를 아래와 같이 수정해준다.

from twisted.internet.interfaces import IReactorFDSet

import sys

try:
    from asyncio import get_event_loop, set_event_loop_policy, WindowsSelectorEventLoopPolicy
except ImportError:
    raise ImportError("Requires asyncio.")

if sys.platform == 'win32':
    set_event_loop_policy(WindowsSelectorEventLoopPolicy())

# As per ImportError above, this module is never imported on python 2, but

 

출처 :

https://stackoverflow.com/questions/58908293/i-keep-getting-notimplementederror-error-when-starting-django-server

 

I keep getting NotImplementedError error when starting django server

Below is a full trace of the error. Please let me know what could fix this issue: (env) C:\Users\LENOVO\Desktop\SD\backend>python manage.py runserver Watching for file changes with StatRelo...

stackoverflow.com

 

 

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

위의것 보다 더 간단한 방법이 있었다.

 

 

얼마전 깃허브에 어느 분이 답글을 달아주셨는데

https://github.com/django/channels/issues/969#issuecomment-596746621

 

create_unix_connection NotImplemented in asyncio · Issue #969 · django/channels

I'm new to channels and trying to take another look after the jump to version 2. I'm running Windows 10 with PyCharm as my IDE using Django 1.11.8, Channels 2.0.2, asgiref 2.2.0, channels-r...

github.com

에서

말해주길

" 프로젝트 폴더 내의 __init__.py 내에 아래의 코드를 추가하면 됩니다." 라는 내용이고

# https://github.com/django/channels/issues/969#issuecomment-596746621
## /mysite/__init__.py

import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

 

 

확인해보니 정상적으로 돌아간다.

 

Comments