주피터 노트북 장고 실행 질문입니다.
596
작성한 질문수 3
수업에 맞게 notebook을 실행해보았는데 계속 에러가 나네요.
아무리 찾아봐도 고칠수없어 질문 드립니다.
--------------------------------------------------------------------------- SynchronousOnlyOperation Traceback (most recent call last) C:\ProgramData\Anaconda3\envs\askcompany\lib\site-packages\IPython\core\formatters.py in __call__(self, obj) 700 type_pprinters=self.type_printers, 701 deferred_pprinters=self.deferred_printers) --> 702 printer.pretty(obj) 703 printer.flush() 704 return stream.getvalue() C:\ProgramData\Anaconda3\envs\askcompany\lib\site-packages\IPython\lib\pretty.py in pretty(self, obj) 392 if cls is not object \ 393 and callable(cls.__dict__.get('__repr__')): --> 394 return _repr_pprint(obj, self, cycle) 395 396 return _default_pprint(obj, self, cycle) C:\ProgramData\Anaconda3\envs\askcompany\lib\site-packages\IPython\lib\pretty.py in _repr_pprint(obj, p, cycle) 698 """A pprint that just redirects to the normal repr function.""" 699 # Find newlines and replace them with p.break_() --> 700 output = repr(obj) 701 lines = output.splitlines() 702 with p.group(): C:\ProgramData\Anaconda3\envs\askcompany\lib\site-packages\django\db\models\query.py in __repr__(self) 250 251 def __repr__(self): --> 252 data = list(self[:REPR_OUTPUT_SIZE + 1]) 253 if len(data) > REPR_OUTPUT_SIZE: 254 data[-1] = "...(remaining elements truncated)..." C:\ProgramData\Anaconda3\envs\askcompany\lib\site-packages\django\db\models\query.py in __iter__(self) 274 - Responsible for turning the rows into model objects. 275 """ --> 276 self._fetch_all() 277 return iter(self._result_cache) 278 C:\ProgramData\Anaconda3\envs\askcompany\lib\site-packages\django\db\models\query.py in _fetch_all(self) 1259 def _fetch_all(self): 1260 if self._result_cache is None: -> 1261 self._result_cache = list(self._iterable_class(self)) 1262 if self._prefetch_related_lookups and not self._prefetch_done: 1263 self._prefetch_related_objects() C:\ProgramData\Anaconda3\envs\askcompany\lib\site-packages\django\db\models\query.py in __iter__(self) 55 # Execute the query. This will also fill compiler.select, klass_info, 56 # and annotations. ---> 57 results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size) 58 select, klass_info, annotation_col_map = (compiler.select, compiler.klass_info, 59 compiler.annotation_col_map) C:\ProgramData\Anaconda3\envs\askcompany\lib\site-packages\django\db\models\sql\compiler.py in execute_sql(self, result_type, chunked_fetch, chunk_size) 1133 cursor = self.connection.chunked_cursor() 1134 else: -> 1135 cursor = self.connection.cursor() 1136 try: 1137 cursor.execute(sql, params) C:\ProgramData\Anaconda3\envs\askcompany\lib\site-packages\django\utils\asyncio.py in inner(*args, **kwargs) 20 else: 21 if event_loop.is_running(): ---> 22 raise SynchronousOnlyOperation(message) 23 # Pass onwards. 24 return func(*args, **kwargs) SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
답변 3
1
해결했습니다.
비동기 버전이 django 3.01부터 적용되었는데 제버전은 3.0 이였네요
django 최신버전으로 다운하니까 문제 해결되었습니다.
1
아무리 해 보아도 되지 않네요
가상환경의 ipython 에서 주피터 노트북 코드를 복사 붙여넣기 해보면 이상없이 작동하는데
이상하게 주피터 노트북에서만 안되네요;;
재시작도 해보았고, 재설치 해보았고, os.environ 확인해 보아서 재대로 들어갔는지 확인도 해보았는데도
안되네요..
0
안녕하세요.
공식문서 https://docs.djangoproject.com/en/4.0/topics/async/ 에서도 안내되듯이, DJANGO_ALLOW_ASYNC_UNSAFE 환경변수를 아래와 같이 추가로 세팅하셨다면 해당 오류는 발생하시지 않습니다.
혹시 DJANGO_ALLOW_ASYNC_UNSAFE 환경변수를 설정하는 코드를 추가하신 후에, 해당 셀부터 django.setup() 셀까지 다시 실행하지 않으신 것은 아니실까요? 쥬피터 노트북의 상단 kernal 메뉴의 "Restart & Run All" 메뉴를 통해 다시 실행해보시겠어요?
아래와 같이 DJANGO_ALLOW_ASYNC_UNSAFE 환경변수를 세팅하지 않으면 말씀하신 오류가 발생하고
해당 환경변수를 세팅하면 오류없이 쿼리셋 코드가 동작을 할 것입니다.
차근차근 확인해보세요.
화이팅입니다. :-)
안녕하세요.
0
56
1
[OneToOne Field Demo] get_user_model() 메서드를 활용해야 하는 이유?
0
278
1
useEffect 훅에서 else 유무에 따른 결과
0
217
1
useAxios 훅의 dependency array 설정
0
251
1
useEffect에서 변수 업데이트 관련 질문
0
384
1
rest_framework.generics.CreateAPIView의 model 속성 유무
0
273
1
bootstrap4
0
474
4
리뉴얼 강의가 오픈이 되면 기존 강의는 더이상 못보는걸까요
1
368
1
admin form에서 앞선 필드 선택 후 다른 필드 select widget 구성하는 방법
0
576
3
useState는 필수일까요?
0
265
1
python manage.py makemigrations instagram 시 created_at default 오류가 발생합니다.
0
604
4
Django allauth를 사용한 소셜 로그인 시 에러
0
656
1
프로젝트명 변경 뒤, 디버그툴바+디버그모드 사용 시 에러
0
558
2
useLocalStorage() 함수 사용여부
0
233
1
django에 LOGIN_URL = '/accounts/login/'의 의미?
0
451
1
리듀서의 의미 재확인
0
432
1
simple-jwt Refresh Token 사용 노하우
0
902
2
docker compose 를 통한 배포 관련 오류 문의
0
679
1
파이썬 속도 장고 관련 궁금한게 있습니다.
0
368
1
is_like_user
0
234
1
related_name 오류
0
275
1
re_path 오류
0
262
1
re_path url
0
251
1
No post matches the given query
0
664
2





