Python callback function usage Example Analysis, python callback function
This example describes the usage of the python callback function. 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.