Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: There is no current event loop in thread 'Thread-1'. #30

Closed
luckydonald opened this issue Apr 18, 2017 · 7 comments
Closed

Comments

@luckydonald
Copy link

luckydonald commented Apr 18, 2017

ERROR    teleflask.server.mixins._execute_command: 
         Failed calling command '/test' (<function test at 0x10f7836a8>):
         Traceback (most recent call last):
           File "/path/to/teleflask/teleflask/server/mixins.py", line 499, in _execute_command
             self.process_result(update, func(update, text))
           File "/path/to/teleflask/teleflask/server/base.py", line 526, in process_result
             from ..messages import Message
           File "/path/to/teleflask/teleflask/messages.py", line 230, in <module>
             class DocumentMessage(Message):
           File "/path/to/teleflask/teleflask/messages.py", line 315, in DocumentMessage
             def send(self, sender: PytgbotApiBot, receiver, reply_id)->PytgbotApiMessage:
           File "/path/to/teleflask/virtualenv3.6.venv/lib/python3.6/site-packages/backoff/_decorator.py", line 141, in decorate
             if asyncio.Task.current_task() is not None:
           File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 671, in get_event_loop
             return get_event_loop_policy().get_event_loop()
           File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 583, in get_event_loop
             % threading.current_thread().name)
         RuntimeError: There is no current event loop in thread 'Thread-1'.

So what fails is:

asyncio.Task.current_task()

When calling teleflask/messages.py:315.
The actual fail in backoff is _decorator.py (function def decorate(target) after asyncio.iscoroutinefunction(target) was false.

For reference, this is luckydonald/teleflask@777953, running examples/example2.py. (Flask internal debug server)
Mac OS 10.9.5
Python 3.6.0 (via brew)

Python 3.6.0 (default, Jan  1 2017, 18:45:22) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin

backoff: Maybe 1.4.0?

python -c 'from backoff import __version__ as v; print(v)'
importError: cannot import name '__version__'
@bgreen-litl
Copy link
Member

@rutsky any thoughts on how to handle this?

I'm guessing there is an event loop in a background thread? The safety check we have here https://github.com/litl/backoff/blob/master/backoff/_decorator.py#L65 is what is blowing up.

@rutsky
Copy link
Contributor

rutsky commented Apr 20, 2017

@bgreen-litl this is indeed bug in safety check. I haven't expected that missing global event loop will blow Task.current_task() in such way.
Take a look at #31 adding unit tests for that and fixing it.

@bgreen-litl
Copy link
Member

@rutsky thank you! @luckydonald I will get a roll a 1.4.1 release with this fix. Thanks for the report.

@luckydonald
Copy link
Author

luckydonald commented Apr 21, 2017

👍 Awesome, thanks!
Btw, could you add a __version__ = "1.4.1" to the package root?

@bgreen-litl
Copy link
Member

bgreen-litl commented Apr 21, 2017

backoff==1.4.1 is released

@luckydonald I also exposed a __version__ attribute in the package root

@luckydonald
Copy link
Author

Yeah! I'll try later today

@luckydonald
Copy link
Author

Works. Fantastic.

luckydonald added a commit to luckydonald/teleflask that referenced this issue May 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants