[New-bugs-announce] [issue22112] '_UnixSelectorEventLoop' object has no attribute 'create_task'

Daniel Greenfeld report at bugs.python.org
Thu Jul 31 04:40:18 CEST 2014

New submission from Daniel Greenfeld:


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
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))]

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)

assignee: docs at python
components: Documentation, Macintosh, asyncio
messages: 224374
nosy: docs at python, gvanrossum, haypo, pydanny, yselivanov
priority: normal
severity: normal
status: open
title: '_UnixSelectorEventLoop' object has no attribute 'create_task'
versions: Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list