Example analysis of Python callback function usage

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.