This article mainly introduces the usage of the python callback function, analyzes in detail the common call methods, and introduces the usage skills of the Python callback function, for more information about how to use the python callback function, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
There are always some interfaces between software modules. in terms of calling methods, they can be divided into three types: synchronous call, callback and Asynchronous call. Synchronous call is a blocking call. the caller must wait for the execution of the other party to complete before returning. it is a one-way call. callback is a two-way call mode, that is, the called party also calls the other party's interface when the interface is called. Asynchronous call is a mechanism similar to messages or events, but its call direction is the opposite, when an interface service receives a message or an event, it proactively notifies the customer (that is, the customer's interface ). Callback and Asynchronous call are closely related. generally, callback is used to register asynchronous messages and message notifications are implemented through asynchronous calls. Synchronous calling is the simplest of the three, and callback is often the basis of asynchronous calling. Therefore, we will focus on the implementation of callback mechanisms in different software architectures.
# Call. pyimport calleddef 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. pyin called. py test_call () in callbackin call. pyjoe @ joe :~ /Test/python $
I hope this article will help you with Python programming.