dabeaz / curio

Good Curio!
Other
4.04k stars 244 forks source link

'Intertask Communication' example from the tutorial raises TypeError #316

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi David,

I am going through the tutorial and I came across the following error when trying to run the Intertask Communication example. Thought to let you know.

(venv) ~/delete: python curio_tutorial.py
Task Crash: Task(id=3, name='dispatcher', state='TERMINATED')
Traceback (most recent call last):
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/kernel.py", line 731, in kernel_run
    trap = current.send(current._trap_result)
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/task.py", line 171, in send
    return self._send(value)
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/task.py", line 175, in _task_runner
    return await coro
  File "curio_tutorial.py", line 8, in dispatcher
    async for msg in messages:
TypeError: 'async for' requires an object with __aiter__ method, got Queue
Task Crash: Task(id=4, name='subscriber', state='TERMINATED')
Traceback (most recent call last):
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/kernel.py", line 731, in kernel_run
    trap = current.send(current._trap_result)
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/task.py", line 171, in send
    return self._send(value)
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/task.py", line 175, in _task_runner
    return await coro
  File "curio_tutorial.py", line 21, in subscriber
    async for msg in queue:
TypeError: 'async for' requires an object with __aiter__ method, got Queue
Task Crash: Task(id=5, name='subscriber', state='TERMINATED')
Traceback (most recent call last):
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/kernel.py", line 731, in kernel_run
    trap = current.send(current._trap_result)
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/task.py", line 171, in send
    return self._send(value)
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/task.py", line 175, in _task_runner
    return await coro
  File "curio_tutorial.py", line 21, in subscriber
    async for msg in queue:
TypeError: 'async for' requires an object with __aiter__ method, got Queue
Task Crash: Task(id=6, name='subscriber', state='TERMINATED')
Traceback (most recent call last):
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/kernel.py", line 731, in kernel_run
    trap = current.send(current._trap_result)
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/task.py", line 171, in send
    return self._send(value)
  File "/home/diogo/delete/venv/lib/python3.8/site-packages/curio/task.py", line 175, in _task_runner
    return await coro
  File "curio_tutorial.py", line 21, in subscriber
    async for msg in queue:
TypeError: 'async for' requires an object with __aiter__ method, got Queue

ps: All the remaining examples run as expected.

dabeaz commented 4 years ago

Oops. For queues, you need to use .get(), not iteration. I've patched the docs. Good catch.

ghost commented 4 years ago

Thanks, David. Please feel free to close the issue.