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

Exception when calling Task.get_stack in DEBUG mode #163

Closed
GoogleCodeExporter opened this issue Apr 10, 2015 · 7 comments
Closed

Exception when calling Task.get_stack in DEBUG mode #163

GoogleCodeExporter opened this issue Apr 10, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

When running asyncio in debug mode (e.g. by setting environment variable 
PYTHONASYNCIODEBUG) and trying Task.get_stack, an exception is raised because 
the _CoroWrapper class is not a generator (I assume, not an expert on generator 
internals). The attached file will reproduce this issue on asyncio 0.4.1.

The exception produced looks like this:
Traceback (most recent call last):
  File "asyncio_stack_exc.py", line 14, in <module>
    loop.run_until_complete(test_outer())
  File "/home/javex/.virtualenvs/misc/lib/python3.3/site-packages/asyncio/base_events.py", line 208, in run_until_complete
    return future.result()
  File "/home/javex/.virtualenvs/misc/lib/python3.3/site-packages/asyncio/futures.py", line 243, in result
    raise self._exception
  File "/home/javex/.virtualenvs/misc/lib/python3.3/site-packages/asyncio/tasks.py", line 283, in _step
    result = next(coro)
  File "/home/javex/.virtualenvs/misc/lib/python3.3/site-packages/asyncio/tasks.py", line 50, in __next__
    return next(self.gen)
  File "/home/javex/.virtualenvs/misc/lib/python3.3/site-packages/asyncio/tasks.py", line 84, in coro
    res = func(*args, **kw)
  File "asyncio_stack_exc.py", line 11, in test_outer
    t.print_stack()
  File "/home/javex/.virtualenvs/misc/lib/python3.3/site-packages/asyncio/tasks.py", line 228, in print_stack
    for f in self.get_stack(limit=limit):
  File "/home/javex/.virtualenvs/misc/lib/python3.3/site-packages/asyncio/tasks.py", line 197, in get_stack
    f = self._coro.gi_frame
AttributeError: 'CoroWrapper' object has no attribute 'gi_frame'

The source of the issue (roughly) is this line: 
https://code.google.com/p/tulip/source/browse/asyncio/tasks.py#91

I think the most easy (but not necessarily the best) fix would be to modify the 
"get_stack" method to check whether "self._coro" 
(https://code.google.com/p/tulip/source/browse/asyncio/tasks.py#197) is an 
instance of CoroWrapper (in the same manner the former half of iscoroutine 
works https://code.google.com/p/tulip/source/browse/asyncio/tasks.py#110).

So one could do something like this:
if _DEBUG:
    f = self._coro.gen.gi_frame
else:
    f = self._coro.gi_frame

Which should work in this case. However, possibly some other code paths also 
rely on the assumption that the coroutine actually is a generator directly so 
maybe there are other places to fix.

Original issue reported on code.google.com by florian....@gmail.com on 31 Mar 2014 at 6:41

Attachments:

@GoogleCodeExporter
Copy link
Author

Hey, good call.  Since CoroWrapper tries to emulate the API of a generator, I 
think we should just add some properties to that class to emulate gi_frame (and 
its brethren, gi_running and gi_code). Try the attached. (It needs a unit test 
still.)

Original comment by gvanrossum@gmail.com on 1 Apr 2014 at 5:47

  • Changed state: Accepted

Attachments:

@GoogleCodeExporter
Copy link
Author

See also http://bugs.python.org/issue21209, which reports a different problem 
with CoroWrapper.

Original comment by gvanrossum@gmail.com on 13 Apr 2014 at 8:44

@GoogleCodeExporter
Copy link
Author

corowrapper-fix.diff lacks unit tests. A test calling print_stack() and/or 
get_stack() on CoroWrapper is needed.

Original comment by victor.s...@gmail.com on 14 Apr 2014 at 2:17

@GoogleCodeExporter
Copy link
Author

That's why I haven't committed it yet. :-( Hopefully I can sprint on this (and 
the Python issue, which also has a fix but no test) tomorrow morning at the 
PyCon sprints.

Original comment by gvanrossum@gmail.com on 14 Apr 2014 at 2:22

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

Here's a fix with unittests (fix163.diff).

Original comment by gu...@dropbox.com on 15 Apr 2014 at 1:11

Attachments:

@GoogleCodeExporter
Copy link
Author

the patch looks good ;)

Original comment by yseliva...@gmail.com on 15 Apr 2014 at 2:35

@GoogleCodeExporter
Copy link
Author

This issue was closed by revision aad393880c50.

Original comment by gvanrossum@gmail.com on 15 Apr 2014 at 7:04

  • Changed state: Fixed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant