Message224374
Problem
========
The documentation on asyncio provides an example of a parallel execution of tasks. The code is at: https://docs.python.org/3/library/asyncio-task.html#example-parallel-execution-of-tasks
``` python
import asyncio
@asyncio.coroutine
def factorial(name, number):
f = 1
for i in range(2, number+1):
print("Task %s: Compute factorial(%s)..." % (name, i))
yield from asyncio.sleep(1)
f *= i
print("Task %s: factorial(%s) = %s" % (name, number, f))
loop = asyncio.get_event_loop()
tasks = [
loop.create_task(factorial("A", 2)),
loop.create_task(factorial("B", 3)),
loop.create_task(factorial("C", 4))]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()
```
Unfortunately, when I try to run this sample code on Python 3.4.1, I run into an error. Specifically, the `loop.create_task()` method does not exist:
``` python
Traceback (most recent call last):
File "what_me_asynicio.py", line 14, in <module>
loop.create_task(factorial("A", 2)),
AttributeError: '_UnixSelectorEventLoop' object has no attribute 'create_task'
```
When I perform a dir() on the `loop` object, no `create_task` item is in the result.
System Information
====================
Python Version: 3.4.1
Operating System: OSX 10.9.3
(Also confirmed on Python 3.4.0 in Ubuntu 14.04) |
|
Date |
User |
Action |
Args |
2014-07-31 02:40:18 | pydanny | set | recipients:
+ pydanny, gvanrossum, vstinner, docs@python, yselivanov |
2014-07-31 02:40:18 | pydanny | set | messageid: <1406774418.2.0.505776361437.issue22112@psf.upfronthosting.co.za> |
2014-07-31 02:40:18 | pydanny | link | issue22112 messages |
2014-07-31 02:40:17 | pydanny | create | |
|