How to use python callback functions

  • 2020-04-02 13:21:26
  • OfStack

There are two types of callback functions:


blocking callbacks (also known as synchronous callbacks or just callbacks)
deferred callbacks (also known as asynchronous callbacks)

So, how to implement callback functions in python? Look at the code:


def my_callback(input):
    print "function my_callback was called with %s input" % (input,)

def caller(input, func):
    func(input)

for i in range(5):
    caller(i, my_callback)


Related articles: