RuntimeError: There is no current event loop in thread 'Thread-2'.
gtg7784 opened this issue · 4 comments
gtg7784 commented
neis = neispy.Client()
Client를 만드는 과정에서 에러가 발생합니다.
에러는 아래 로그에 해당합니다.
/home/ubuntu/.local/lib/python3.6/site-packages/neispy/client.py:77: UserWarning: API키가 없습니다, 샘플키로 요청합니다
warnings.warn("API키가 없습니다, 샘플키로 요청합니다", UserWarning)
ERROR:app:Exception on / [POST]
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "app.py", line 38, in chat
response_sent_text = choice_message(text)
File "app.py", line 57, in choice_message
'급식': get_meal(text),
File "app.py", line 83, in get_meal
neis = neispy.Client()
File "/home/ubuntu/.local/lib/python3.6/site-packages/neispy/client.py", line 535, in __init__
self.loop = asyncio.get_event_loop()
File "/usr/lib/python3.6/asyncio/events.py", line 694, in get_event_loop
return get_event_loop_policy().get_event_loop()
File "/usr/lib/python3.6/asyncio/events.py", line 602, in get_event_loop
% threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-2'.
INFO:werkzeug:162.158.79.153 - - [12/Sep/2020 13:39:31] "POST / HTTP/1.1" 500 -
asyncio 관련 에러같습니다.
SaidBySolo commented
neispy는 thread safe하지 않습니다.
SaidBySolo commented
클라이언트 선언을 해당스레드에서 진행해주세요
kijk2869 commented
타 쓰레드에서 사용하고 싶으신 경우 from neispy.client import _Client
을 사용하여 코루틴을 직접 다루셔야 합니다.
gtg7784 commented
아 네 확인했습니다. 감사합니다.