aiomqtt icon indicating copy to clipboard operation
aiomqtt copied to clipboard

Bugfix: Update client.py

Open miili opened this issue 2 years ago • 1 comments

Catching right exception

miili avatar Aug 03 '22 10:08 miili

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

frederikaalund avatar Aug 03 '22 12:08 frederikaalund

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 😋

empicano avatar Nov 19 '22 23:11 empicano