RuntimeError: await wasn't used with future
Closed this issue · 13 comments
Running the example.py script (or using this lib via a home assistant integration) results in an immediate error (I'm not really familiar with python asyncio to try to fix this myself):
$ python example.py 172.17.2.17
DEBUG:asyncio:Using selector: EpollSelector
DEBUG:brother:Initializing device 172.17.2.17
Traceback (most recent call last):
File "/srv/homeassistant/example.py", line 50, in <module>
loop.run_until_complete(main())
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/srv/homeassistant/example.py", line 31, in main
brother = await Brother.create(
File "/srv/homeassistant/lib/python3.9/site-packages/brother/__init__.py", line 95, in create
await instance.initialize()
File "/srv/homeassistant/lib/python3.9/site-packages/brother/__init__.py", line 120, in initialize
_, errstatus, errindex, _ = await hlapi.getCmd(*request_args, *tuple(oids))
RuntimeError: await wasn't used with future
ERROR:asyncio:Task was destroyed but it is pending!
task: <Task pending name='Task-2' coro=<BaseEventLoop.create_datagram_endpoint() running at /usr/lib/python3.9/asyncio/base_events.py:1380> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fbb365fa0>()]>>
ERROR:asyncio:Task was destroyed but it is pending!
task: <Task pending name='Task-3' coro=<AsyncioDispatcher.handle_timeout() running at /srv/homeassistant/lib/python3.9/site-packages/pysnmp/carrier/asyncio/dispatch.py:55> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fbb365f10>()]>>
Exception ignored in: <coroutine object BaseEventLoop.create_datagram_endpoint at 0x7fbb472340>
Traceback (most recent call last):
File "/usr/lib/python3.9/asyncio/base_events.py", line 1382, in create_datagram_endpoint
File "/usr/lib/python3.9/asyncio/selector_events.py", line 700, in close
File "/usr/lib/python3.9/asyncio/base_events.py", line 746, in call_soon
File "/usr/lib/python3.9/asyncio/base_events.py", line 510, in _check_closed
RuntimeError: Event loop is closed
I tried both 2.0.0 and current git with python 3.9 in home assistant virtual environment and 3.11 in a clean Fedora 37 installation, the error is always the same.
Yes, I know about the issue, it is related to pysnmplib
. I was too quick with merging branch and release new version. Please use version 1.2.3
.
Hmm, I see the same error even with 1.2.3:
$ pip install brother
...
Installing collected packages: pysnmp-pyasn1, pycryptodomex, pysnmp-pysmi, pysnmplib, brother
Successfully installed brother-1.2.3 pycryptodomex-3.16.0 pysnmp-pyasn1-1.1.2 pysnmp-pysmi-1.1.10 pysnmplib-5.0.20
$ wget https://raw.githubusercontent.com/bieniu/brother/1.2.3/example.py
$ python example.py 172.17.2.17
DEBUG:asyncio:Using selector: EpollSelector
DEBUG:brother:Using host: 172.17.2.17
Traceback (most recent call last):
File "/home/test/example.py", line 48, in <module>
loop.run_until_complete(main())
File "/usr/lib64/python3.11/asyncio/base_events.py", line 650, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/test/example.py", line 32, in main
data = await brother.async_update()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/test/.local/lib/python3.11/site-packages/brother/__init__.py", line 98, in async_update
if not (raw_data := await self._get_data()):
^^^^^^^^^^^^^^^^^^^^^^
File "/home/test/.local/lib/python3.11/site-packages/brother/__init__.py", line 232, in _get_data
await self._init_device()
File "/home/test/.local/lib/python3.11/site-packages/brother/__init__.py", line 302, in _init_device
errindication, errstatus, errindex, _ = await hlapi.getCmd(*request_args, *oids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: await wasn't used with future
ERROR:asyncio:Task was destroyed but it is pending!
task: <Task pending name='Task-2' coro=<BaseEventLoop.create_datagram_endpoint() running at /usr/lib64/python3.11/asyncio/base_events.py:1389> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Exception ignored in: <coroutine object BaseEventLoop.create_datagram_endpoint at 0x7f365aa428f0>
Traceback (most recent call last):
File "/usr/lib64/python3.11/asyncio/base_events.py", line 1391, in create_datagram_endpoint
File "/usr/lib64/python3.11/asyncio/selector_events.py", line 831, in close
File "/usr/lib64/python3.11/asyncio/base_events.py", line 758, in call_soon
File "/usr/lib64/python3.11/asyncio/base_events.py", line 519, in _check_closed
RuntimeError: Event loop is closed
ERROR:asyncio:Task was destroyed but it is pending!
task: <Task pending name='Task-3' coro=<AsyncioDispatcher.handle_timeout() running at /home/test/.local/lib/python3.11/site-packages/pysnmp/carrier/asyncio/dispatch.py:55> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Version 1.2.3
is not compatible with Python 3.11.
And you have to downgrade pysnmplib
.
Oh, that would be the missing part as 1.2.3 was reporting the same error even with python 3.9.0. Anyway everything works well with pysnmplib 5.0.19.
Thanks.
Is this the same issue I am having? https://www.reddit.com/r/homeassistant/comments/zfnsu6/brother_printers/
Yeah, looks like it's the same issue.
@lionslair If you have problem with Home Assistant, please open an issue in HA repository. HA is using brother==2.0.0
and pysnmplib==5.0.15
and this problem should not accur.
@jirkade I published brother=2.0.1
with pinned pysnmplib
version. This version works with Python<3.11.
Sorry. I was just following the links for HA
I will try those explicit modules