Browsing Chinese (Simplified) translation

522 of 2684 results
522.
def largeFibonnaciNumber():
"""
Represent a long running blocking function by calculating
the TARGETth Fibonnaci number
"""
TARGET = 10000

first = 0
second = 1

for i in xrange(TARGET - 1):
new = first + second
first = second
second = new

return second

from twisted.internet import threads, reactor

def fibonacciCallback(result):
"""
Callback which manages the largeFibonnaciNumber result by
printing it out
"""
print "largeFibonnaciNumber result =", result
# make sure the reactor stops after the callback chain finishes,
# just so that this example terminates
reactor.stop()

def run():
"""
Run a series of operations, deferring the largeFibonnaciNumber
operation to a thread and performing some other operations after
adding the callback
"""
# get our Deferred which will be called with the largeFibonnaciNumber result
d = threads.deferToThread(largeFibonnaciNumber)
# add our callback to print it out
d.addCallback(fibonacciCallback)
print "1st line after the addition of the callback"
print "2nd line after the addition of the callback"

if __name__ == '__main__':
run()
reactor.run()
type: Content of: <html><body><pre>
There are line breaks here. Each one represents a line break. Start a new line in the equivalent position in the translation.
There are leading/trailing spaces here. Each one represents a space character. Enter a space in the equivalent position in the translation.
def largeFibonnaciNumber():
"""
一个需要长时间运行的阻塞函数,求第 TARGET 个 Fibonnaci 数
"""
TARGET = 10000

first = 0
second = 1

for i in xrange(TARGET - 1):
new = first + second
first = second
second = new

return second

from twisted.internet import threads, reactor

def fibonacciCallback(result):
"""
回调函数,打印 largeFibonnaciNumber 的结果
"""
print "largeFibonnaciNumber result =", result
# 在回调链处理完成后终止 reactor,
# 这样才能让例子程序结束运行
reactor.stop()

def run():
"""
Run a series of operations, deferring the largeFibonnaciNumber
operation to a thread and performing some other operations after
adding the callback
"""
# get our Deferred which will be called with the largeFibonnaciNumber result
d = threads.deferToThread(largeFibonnaciNumber)
# add our callback to print it out
d.addCallback(fibonacciCallback)
print "1st line after the addition of the callback"
print "2nd line after the addition of the callback"

if __name__ == '__main__':
run()
reactor.run()
Translated and reviewed by Liu, Kun
Located in howto/gendefer.xhtml:230
522 of 2684 results

This translation is managed by Exoweb FOSS, assigned by Twisted.

You are not logged in. Please log in to work on translations.