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.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.