1 co- coroutines 2 3 awaitable Objects,4Awaitable Objects usually consists of__await__() generation, and5Coroutine objects is made by asyncdeffunction defined by the keywordreturnthe awaitable Objects.6 Note,7by Types.coroutine ()orasyncio.coroutine () decorated Generator iterator object (generator iterator objects)8is not through__await__() the generated awaitable Objects.9 TenObject.__await__(self) mustreturna iterator that is used to generate awaitable Objects. One for example, Asyncio. The future executes this method one-compatible await expression. ASee also PEP 492 foradditional information about awaitable objects. - - coroutine Objects, theCoroutine objects is awaitable objects, is a__await__()returnof iterator, -Coroutine's execution is to__await__()returniteration of the iterator. Like iterator, - when Coroutine finishes executing raises stopiteration, the Value property of this exception is the result of the execution return. -If Coroutine raises an exception, this exception will be'Bubble Type'return. Coroutines can not directly + Raisean unprocessed stopiteration exceptions. - + Coroutines has the following methods (similar to generator), but unlike generators, coroutines is not AThe iterations provide direct support. Python version 3.5.2, followed by several await returns on a coroutine at RuntimeError exception. - - coroutine.send (value) -Start or resume the execution of Coroutine. If the parameter is value =None, for pre-activation of the coroutine. - if value is not none, this method is equivalent to iterator's send () method, which causes the coroutine to pause. -The return of the method (returnValue, Stopiteration,orOther exception) have been described above. in - Coroutine.throw (type[, value[, Traceback]) toIn CoroutineRaisespecified exception. + This method corresponds to the throw () method in iterator, which causes the coroutine to pause - the coroutine.close () * causes the Coroutine to initialize and exit. Corresponds to the close () method of the iterator. $ Panax Notoginseng Asynchronous Iterators -A asynchronous iterable by calling__aiter__() get a asynchronous iterator. the asynchronous iterators can be used in an async declaration. + AObject.__aiter__(self) the returns a asynchronous iterator object. + -Object.__anext__(self) $ returns a Awaitable object from iterator. When the iterator is over, $ Raisestopasynciteration Error Exception - - asynchronous Iterable An example of object, the - classReader:WuyiAsyncdefReadLine (self): the ... - Wu def __aiter__(self): - return Self About $Asyncdef __anext__(self): -val =await Self.readline () - ifval = = b"': - Raisestopasynciteration A returnVal + the asynchronous Context Managers, - Asynchronous Context Manager is a context manager that can pause execution. $ asynchronous context managers can be declared with the async with keyword. theObject.__aenter__(self) theAnd__enter__() is similar, except that the method must return a Awaitable object. the theObject.__aexit__(self, exc_type, Exc_value, Traceback), -And__exit__() is similar, except that the method must return a Awaitable object. in the Asynchronous the context manager example, the classAsynccontextmanager: AboutAsyncdef __aenter__(self): theAwait log ('Entering context') the theAsyncdef __aexit__(self, exc_type, exc, TB): +Await log ('Exiting Context') - the Reference,BayiPython Doc. https://docs.python.org/3/reference/datamodel.html#coroutines
Python coprocessor-Coroutines