Changes between Version 219 and Version 220 of WikiStart


Ignore:
Timestamp:
09/15/2012 09:19:59 AM (6 years ago)
Author:
Jean-Paul Calderone
Comment:

Fix error logging; demonstrate task.react as the way to run the reactor

Legend:

Unmodified
Added
Removed
Modified
  • WikiStart

    v219 v220  
    224224{{{
    225225#!python
    226 from twisted.internet import reactor, protocol, defer, endpoints
     226import sys
     227
     228from twisted.internet import protocol, defer, endpoints, task
    227229from twisted.mail import imap4
    228 from twisted.python import log, failure
     230from twisted.python import failure
    229231
    230232@defer.inlineCallbacks
    231 def main(username="alice", password="secret",
     233def main(reactor, username="alice", password="secret",
    232234         strport="ssl:host=example.com:port=993"):
    233235    endpoint = endpoints.clientFromString(reactor, strport)
     
    239241        yield client.select('INBOX')
    240242        info = yield client.fetchEnvelope(imap4.MessageSet(1))
    241         print info[1]['ENVELOPE'][1]
     243        print 'First message subject:', info[1]['ENVELOPE'][1]
    242244    except:
    243         log.err(failure.Failure(), "IMAP4 client interaction failed")
    244     reactor.stop()
    245 
    246 import sys
    247 main(*sys.argv[1:])
    248 reactor.run()
     245        print "IMAP4 client interaction failed"
     246        failure.Failure().printTraceback()
     247
     248task.react(main, sys.argv[1:])
    249249}}}
    250250