dabeaz / curio

Good Curio!
Other
4.04k stars 243 forks source link

The Getting Started example in the tutorial doesn't work for me #200

Closed DigitalChiller closed 7 years ago

DigitalChiller commented 7 years ago

I decided to try out curio, so I copied a tutorial example https://curio.readthedocs.io/en/latest/tutorial.html#getting-started and ran it in the Python3 interpreter (same when you put it in a file, except you don't have to press ctrl-c for the last Traceback to appear):

Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import curio
>>> async def countdown(n=10):
...     while n > 0:
...         print('T-minus', n)
...         await curio.sleep(1)
...         n -= 1
... 
>>> curio.run(countdown, 10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: run() takes 1 positional argument but 2 were given
>>> curio.run(countdown)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/curio/kernel.py", line 1066, in run
    return kernel.run(coro, timeout=timeout)
  File "/usr/local/lib/python3.5/dist-packages/curio/kernel.py", line 324, in run
    ret_val, ret_exc = self._runner.send((coro, timeout))
  File "/usr/local/lib/python3.5/dist-packages/curio/kernel.py", line 837, in _run_coro
    main_task = _new_task(coro) if coro else None
  File "/usr/local/lib/python3.5/dist-packages/curio/kernel.py", line 465, in _new_task
    task = Task(coro, daemon)
  File "/usr/local/lib/python3.5/dist-packages/curio/task.py", line 54, in __init__
    self._send = coro.send     # Bound coroutine methods
AttributeError: 'function' object has no attribute 'send'
>>> # let's press ctrl-c
... 
>>> 
Exception ignored in: <bound method Task.__del__ of Task(id=1, name='countdown', <function countdown at 0x7f195c849f28>, state='INITIAL')>
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/curio/task.py", line 65, in __del__
    self.coro.close()
AttributeError: 'function' object has no attribute 'close'
KeyboardInterrupt
>>> 
dabeaz commented 7 years ago

I'm in a transitional period of preparing a new release and lot of things have changed. Documentation is currently tracking the master branch of Curio in Github. So, I would try that instead of any version downloaded from pypi.

DigitalChiller commented 7 years ago

Jup, the git version works fine. Thanks for the help :)