aiomqtt
aiomqtt copied to clipboard
Bugfix: Update client.py
Catching right exception
Hi miili. Thanks for opening this pull request. Let me have a look. :)
The intention of the AttributeError
is to have a fallback for python 3.6 and below. Specifically, because Python 3.7 added get_running_loop
.
In python 3.6, the following occurs:
>>> asyncio.get_running__loop()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'asyncio' has no attribute 'get_running_loop'.
This is exactly what we want. In the exception handler for this AttributeError
, we fall back to the older asyncio.get_event_loop
.
Are you sure that you have a running event loop when you call connect? Because if you don't, then you get a RuntimeError
. E.g.:
>>> asyncio.get_running_loop()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: no running event loop
I think we can close this. In 0.14.0
we dropped Python 3.6 support, and the try/except
of this PR was removed. If there's anything left unclear, simply open a new issue 😋