some source code about twisted

This commit is contained in:
JamesonHuang
2015-06-15 22:20:58 +08:00
parent 8791e644e5
commit dff86defdb
1113 changed files with 407155 additions and 0 deletions

View File

@ -0,0 +1,20 @@
class Countdown(object):
counter = 5
def count(self):
if self.counter == 0:
reactor.stop()
else:
print self.counter, '...'
self.counter -= 1
reactor.callLater(1, self.count)
from twisted.internet import reactor
reactor.callWhenRunning(Countdown().count)
print 'Start!'
reactor.run()
print 'Stop!'

View File

@ -0,0 +1,15 @@
def falldown():
raise Exception('I fall down.')
def upagain():
print 'But I get up again.'
reactor.stop()
from twisted.internet import reactor
reactor.callWhenRunning(falldown)
reactor.callWhenRunning(upagain)
print 'Starting the reactor.'
reactor.run()

View File

@ -0,0 +1,11 @@
def hello():
print 'Hello from the reactor loop!'
print 'Lately I feel like I\'m stuck in a rut.'
from twisted.internet import reactor
reactor.callWhenRunning(hello)
print 'Starting the reactor.'
reactor.run()

View File

@ -0,0 +1,35 @@
import sys
from twisted.python import log
from twisted.internet import defer
"""This example illustrates some Twisted logging basics."""
log.msg('This will not be logged, we have not installed a logger.')
log.startLogging(sys.stdout)
log.msg('This will be logged.')
log.err('This will be logged as an error.')
def bad_callback(result):
xxx
try:
bad_callback()
except:
log.err('The next function call will log the traceback as an error.')
log.err()
d = defer.Deferred()
def on_error(failure):
log.err('The next function call will log the failure as an error.')
log.err(failure)
d.addCallback(bad_callback)
d.addErrback(on_error)
d.callback(True)
log.msg('End of example.')

View File

@ -0,0 +1,5 @@
from twisted.internet import pollreactor
pollreactor.install()
from twisted.internet import reactor
reactor.run()

View File

@ -0,0 +1,2 @@
from twisted.internet import reactor
reactor.run()

View File

@ -0,0 +1,9 @@
import traceback
def stack():
print 'The python stack:'
traceback.print_stack()
from twisted.internet import reactor
reactor.callWhenRunning(stack)
reactor.run()