Changes between Version 5 and Version 6 of FrequentlyAskedQuestions

12/05/06 04:07:38 (15 years ago)



  • FrequentlyAskedQuestions

    v5 v6  
    125125[ spawnProcess] defaults to clearing the environment of child processes as a security feature. You can either provide a dictionary with exactly the name-value pairs you want the child to use, or you can simply pass in {{{os.environ}}} to inherit the complete environment.
    127 === My Deferred or DeferredList never fires, so my program just mysteriously hangs! What's wrong? ===
     127=== My Deferred or !DeferredList never fires, so my program just mysteriously hangs! What's wrong? ===
    129129It really depends on what your program is doing, but the most common cause is this: it is firing -- but it's an error, not a success, and you have forgotten to add an [ errback], so nothing happens. Always add errbacks!
    141141If you have blocking code that you want to use non-blockingly in Twisted, either rewrite it to be non-blocking, or run it in a thread. There is a convenience function, [ deferToThread], to help you with the threaded approach -- but be sure to read [ Using Threads in Twisted].
    143 === I get exceptions.ValueError: signal only works in main thread when I try to run my Twisted program! What's wrong? ===
     143=== I get {{{exceptions.ValueError: signal only works in main thread}}} when I try to run my Twisted program! What's wrong? ===
    145145The default reactor, by default, will install signal handlers to catch events like Ctrl-C, SIGTERM, and so on. However, you can't install signal handlers from non-main threads in Python, which means that {{{}}} will cause an error. Pass the {{{installSignalHandlers=0}}} keyword argument to {{{}}} to work around this.
    147147=== I'm trying to stop my program with sys.exit(), but Twisted seems to catch it! How do I exit my program? ===
     149Use {{{reactor.stop()}}} instead. This will cleanly shutdown the reactor.
    148151=== How do I find out the IP address of the other end of my connection? ===
     153The {{{.transport}}} object (which implements the [ ITransport] interface) offers a pair of methods named [ getPeer] and [ getHost]. {{{getPeer}}} will give you a tuple that describes the address of the system at the other end of the connection. For example:
     157class MyProtocol(protocol.Protocol):
     158    def connectionMade(self):
     159        print "connection from", self.transport.getPeer()
    149162=== Why don't Twisted's network methods support Unicode objects as well as strings? ===
    150163== Perspective Broker ==