A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20141127/d73f0e1a/attachment-0001.py below:

class Return(Exception): def __init__(self, value): self.value = value class Task: def __init__(self, coro): self.coro = coro self.result = None self.done = False def _step(self): try: result = next(self.coro) except Return as exc: result = exc.value self.done = True def __iter__(self): while not self.done: yield self._step() return self.result def trollius_coro(calls): calls.append("enter trollius_coro") yield None calls.append("exit trollius_coro with Return") raise Return(5) def asyncio_coro(calls): calls.append("enter asyncio_coro") coro = trollius_coro(calls) calls.append("asyncio_coro yield from trollius_coro") result = yield from coro calls.append("asyncio_coro returns %r" % result) return result def test(): calls = [] coro = asyncio_coro(calls) # simulate a call to loop.run_until_complete(coro) task = Task(coro) result = yield from task for call in calls: print(call) print("Result: %r" % result) for item in test(): pass

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4