This article mainly introduces the use of Python callback function, the more detailed analysis of the commonly used invocation methods, and examples of the Python callback function using skills, the need for friends can refer to the
There is always a certain interface between software modules, from the way of invocation, they can be divided into three categories: synchronous call, callback and asynchronous call. A synchronous call is a blocking call, the caller waits for the other party to execute before returning, it is a one-way call; The callback is a two-way invocation pattern, that is, the caller also invokes the interface of the other when the interface is invoked; an asynchronous call is a mechanism similar to a message or event, but it is in the opposite direction. The service of an interface will actively notify the client (that is, the interface that invokes the client) when it receives a message or an event occurs. Callback and asynchronous invocation are very closely related, and we usually use callbacks to register asynchronous messages, and to implement notification of messages by asynchronous invocation. Synchronous calls are the simplest of the three, and callbacks are often the basis of asynchronous invocations, so here we focus on the implementation of callback mechanisms in different software architectures.
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23-24 |
#call. PY Import called Def callback (): print ' in callback ' Def Main (): #called. Test () Called.test_call (callback) print "in call.py "Main () #called. Py" ' Def Test (): print "in called.py Test ()" "' Def Test_call (p_call): print" in called.py Test_call () "P_call () joe@joe:~/test/python$ python call.py in called.py Test_call () in callback in call.py joe@joe:~/t est/python$ |
I hope this article will help you with your Python programming.