Function never get called without @inlineCallback

31 Views Asked by At

I was trying to test twisted callback functions and see the below code is working. However, when I remove @inlineCallback in the code, I don't see "Hello" message printed and it seems never executed.

If I use the hello function without for loop inside, then it prints "Hello" without @inlineCallback decorator. How this is possible?

If yield statement doesn't exist, it executes normally; however, if yield statement exists in the function, then it executes only when decorated with @inlineCallback.

How this is possible??

from autobahn.twisted.component import run
from autobahn.twisted.util import sleep

@inlineCallback
def hello():
    print "Hello"
    for i in range(0, 3):
        print "Hello", i
        yield sleep(1)

reactor.callLater(1, hello)
reactor.run()
0

There are 0 best solutions below