[Twisted-Python] Re: reactor.stop

Eugene Coetzee projects at reedflute.com
Mon Aug 16 11:58:05 EDT 2004

Christopher Armstrong wrote:

>On Mon, 16 Aug 2004 11:39:11 +0800, Tsai Li Ming <mailinglist at ltsai.com> wrote:
>>The part that I don't understand is when I import the reactor in my own
>>py files, why will it be the same single reactor that the application
>>uses. Is it something special that twisted is handling or is just a
>>simple python question?
>Well, the reactor module is pretty weird and magical, but in this
>regard, it acts exactly like any python module. When you import any
>module twice, you get the same module.
In fact - reactor is not an package - but a global instance returned by 
class SelectReactor.

from twisted.internet.default.py

def install():
"""Configure the twisted mainloop to be run using the select() reactor.
reactor = SelectReactor()

When the reactor is installed the following code in 
twisted.internet.main.py checks for existing instances of 'reactor'.

def installReactor(reactor):
global addReader, addWriter, removeReader, removeWriter
global iterate, addTimeout, wakeUp
# this stuff should be common to all reactors.
import twisted.internet
import sys
assert not sys.modules.has_key('twisted.internet.reactor'), \
"reactor already installed"
twisted.internet.reactor = reactor
sys.modules['twisted.internet.reactor'] = reactor



Web                 -> www.reedflute.com

More information about the Twisted-Python mailing list