eclipse / paho.mqtt.python

paho.mqtt.python
Other
2.17k stars 723 forks source link

Trio example not working with latest trio version #678

Closed adiroiban closed 8 months ago

adiroiban commented 1 year ago

Hi,

I am trying to run paho with trio.

I am completely new to paho or trio.

I got a copy paste of the example.

I am using:

The traceback

python run-trio.py 
Starting
Socket opened
large write request
misc_loop started
Traceback (most recent call last):
  File "/home/adi/chevah/run-trio.py", line 139, in <module>
    trio.run(TrioAsyncMqttExample().main)
  File "/home/adi/chevah/venv/lib/python3.10/site-packages/trio/_core/_run.py", line 1946, in run
    raise runner.main_task_outcome.error
  File "/home/adi/chevah/run-trio.py", line 129, in main
    async with trio.open_nursery() as nursery:
  File "/home/adi/chevah/venv/lib/python3.10/site-packages/trio/_core/_run.py", line 813, in __aexit__
    raise combined_error_from_nursery
  File "/home/adi/chevah/run-trio.py", line 70, in read_loop
    await trio.hazmat.wait_readable(self.sock)
  File "/home/adi/chevah/venv/lib/python3.10/site-packages/trio/_deprecate.py", line 124, in __getattr__
    raise AttributeError(msg.format(self.__name__, name))
AttributeError: module 'trio' has no attribute 'hazmat'
finished large write

It looks like the hazmat was deprecated https://github.com/python-trio/trio/pull/1722

adiroiban commented 1 year ago

I think the fix is something like this

-await trio.hazmat.wait_readable(self.sock)
+await trio.lowlevel.wait_readable(self.sock)

I tried it and it looks like it's working, I will open a PR :)