Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Can't use functools.partial() to wrap coroutine in debug mode -- bug or not? #241

@gvanrossum

Description

@gvanrossum

In #222 I note that after fixing the original issue (__name__ raises an AttributeError) the example program still fails in debug mode, because of the way partial() is wrapping a CoroWrapper. Should we consider this a bug or a feature? I'm copying the sample program here:

import asyncio
import functools

@asyncio.coroutine
def func(x, y):
    print('func with x = {} and y = {}'.format(x, y))
    yield from asyncio.sleep(0.1)
    print('exit func')


partial_func = asyncio.coroutine(functools.partial(func, 1))

loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(partial_func(2))
finally:
    loop.close()

In non-debug mode this prints

func with x = 1 and y = 2
exit func

but in debug mode I get a traceback:

PYTHONASYNCIODEBUG=1 python3 p.py
<CoroWrapper func() running at p.py:4, created at /Users/guido/src/asyncio/asyncio/coroutines.py:141> was never yielded from
Coroutine object created at (most recent call last):
  File "p.py", line 15, in <module>
    loop.run_until_complete(partial_func(2))

(etc.)

I think the example code is equivalent to

@asyncio.coroutine
def func(x, y):
    ...
@asyncio.coroutine
def partial_func(y):
    return func(1, y)

I think this exposes the bug in the original program -- the final line should really be

    return yield from func(1, y)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions