must call when the button is pressedin this case the doaction(function we have used partial function application to ensure that the first argument given to the doaction(function is string that indicates which button called it so that doaction(is able to decide what action to perform coroutines |coroutines are functions whose processing can be suspended and resumed at specific points sotypicallya coroutine will execute up to certain statementthen suspend execution while waiting for some data at this point other parts of the program can continue to execute (usually other coroutines that aren' suspendedonce the data is received the coroutine resumes from the point it was suspendedperforms processing (presumably based on the data it got)and possibly sending its results to another coroutine coroutines are said to have multiple entry and exit pointssince they can have more than one place where they suspend and resume coroutines are useful when we want to apply multiple functions to the same pieces of dataor when we want to create data processing pipelinesor when we want to have master function with slave functions coroutines can also be used to provide simpler and lower-overhead alternatives to threading few coroutine-based packages that provide lightweight threading are available from the python package indexpypi python org/pypi yield statement in pythona coroutine is function that takes its input from yield expression it may also send results to receiver function (which itself must be coroutinewhenever coroutine reaches yield expression it suspends waiting for dataand once it receives datait resumes execution from that point coroutine can have more than one yield expressionalthough each of the coroutine examples we will review has only one performing independent actions on data if we want to perform set of independent operations on some datathe conventional approach is to apply each operation in turn the disadvantage of this is that if one of the operations is slowthe program as whole must wait for the operation to complete before going on to the next one solution to this is to use coroutines we can implement each operation as coroutine and then start them all off if one is slow it won' affect the others--at least not until they run out of data to process--since they all operate independently figure illustrates the use of coroutines for concurrent processing in the figurethree coroutines (each presumably doing different jobprocess the same two data items--and take different amounts of time to do their work in the figurecoroutine (works quite quicklycoroutine (works slowlyand coroutine (varies once all three coroutines have been given their initial data