Here is an example:
---
import asyncio

def bug():
    raise Exception("error in bar")

@asyncio.coroutine
def work2():
    yield from []
    loop.call_soon(bug)

@asyncio.coroutine
def work():
    yield from work2()

def schedule():
    loop.create_task(work())

loop = asyncio.get_event_loop()
loop.call_soon(schedule)
loop.run_forever()
loop.close()
---

Current output in debug mode:
---
Exception in callback bug() at y.py:3
handle: <Handle bug() at y.py:3 created at y.py:9>
source_traceback: Object created at (most recent call last):
  File "y.py", line 20, in <module>
    loop.run_forever()
  File "/home/haypo/prog/HG/tulip/asyncio/base_events.py", line 244,
in run_forever
    self._run_once()
  File "/home/haypo/prog/HG/tulip/asyncio/base_events.py", line 1083,
in _run_once
    handle._run()
  File "/home/haypo/prog/HG/tulip/asyncio/events.py", line 120, in _run
    self._callback(*self._args)
  File "/home/haypo/prog/HG/tulip/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/home/haypo/prog/HG/tulip/asyncio/coroutines.py", line 79, in __next__
    return next(self.gen)
  File "y.py", line 13, in work
    yield from work2()
  File "/home/haypo/prog/HG/tulip/asyncio/coroutines.py", line 79, in __next__
    return next(self.gen)
  File "y.py", line 9, in work2
    loop.call_soon(bug)
Traceback (most recent call last):
  File "/home/haypo/prog/HG/tulip/asyncio/events.py", line 120, in _run
    self._callback(*self._args)
  File "y.py", line 4, in bug
    raise Exception("error in bar")
Exception: error in bar
---

I don't see how the work() task was scheduled, nor the call to scheduled.

Debug output with the latest patch:
---
Exception in callback bug() at y.py:3
handle: <Handle bug() at y.py:3 created at y.py:9>
source_traceback: Object created at (most recent call last):
  File "y.py", line 19, in <module>
    loop.call_soon(schedule)
  File "y.py", line 19, in <module>
    <injected handle>
  File "/home/haypo/prog/HG/tulip/asyncio/events.py", line 125, in _run
    self._callback(*self._args)
  File "y.py", line 16, in schedule
    loop.create_task(work())
  File "y.py", line 16, in schedule
    <injected task>
  File "/home/haypo/prog/HG/tulip/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/home/haypo/prog/HG/tulip/asyncio/coroutines.py", line 79, in __next__
    return next(self.gen)
  File "y.py", line 13, in work
    yield from work2()
  File "/home/haypo/prog/HG/tulip/asyncio/coroutines.py", line 79, in __next__
    return next(self.gen)
  File "y.py", line 9, in work2
    loop.call_soon(bug)
Traceback (most recent call last):
  File "/home/haypo/prog/HG/tulip/asyncio/events.py", line 125, in _run
    self._callback(*self._args)
  File "y.py", line 4, in bug
    raise Exception("error in bar")
Exception: error in bar
---

Here you can see the full chain: schedule -> work -> work2 -> bug.

Victor

Reply via email to