[Twisted-Python] How can I make twisted and dbus work together?

Matt Goodall matt at pollenation.net
Wed Jan 16 06:40:28 EST 2008


Matt Goodall wrote:
> Matt Goodall wrote:
>> Justin Warren wrote:
>>> On Wed, 2008-01-16 at 17:28 +1100, hwan2265 at mail.usyd.edu.au wrote:
>>>
>>>> But when I was running my code, I got a error:
>>>>
>>>> Traceback (most recent call last):
>>>>   File "dbustwisted.py", line 5, in <module>
>>>>     glib2reactor.install()
>>>>   File "/usr/lib/python2.5/site-packages/twisted/internet/glib2reactor.py",
>>>> line 33, in install
>>>>     return gtk2reactor.install(False)
>>>>   File "/usr/lib/python2.5/site-packages/twisted/internet/gtk2reactor.py",
>>>> line 270, in install
>>>>     installReactor(reactor)
>>>>   File "/usr/lib/python2.5/site-packages/twisted/internet/main.py", line
>>>> 24, in installReactor
>>>>     "reactor already installed"
>>>> AssertionError: reactor already installed
>>> I suspect your problem may be here:
>>>
>>>> if __name__ == "__main__":
>>>>     from twisted.internet import glib2reactor
>>>>     glib2reactor.install()
>>>>     ################################################
>>>>     # I added the 2 lines here and made the program crash
>>>>     ################################################
>>>>
>>>>     from twisted.internet import reactor
>>>       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>
>>> You've already imported glib2reactor, so you shouldn't import the
>>> default reactor as well. Try removing this line.
>> Actually, twisted.internet.reactor is quite magic. It is always the
>> installed reactor. However, if there is no reactor installed the first
>> time it is imported it will automatically install the default (select)
>> reactor.
>>
>> I suspect that the real cause of the problem is that something is doing
>> a "from twisted.internet import reactor", causing the select reactor to
>> be installed, before the above code is getting the chance to install the
>> glib2reactor.
>>
>> Looking at the code it must be a Twisted module that is the culprit.
> 
> And the offending module is ... twisted.protocols.policies. Attached is
> a patch (I'll submit it to Trac as a ticket, too.)


Grepping the Twisted code suggests this is a "problem" that is not
really worth trying to fix fully. It's probably best to just avoid the
problem by making sure you get to install your choice of reactor before
anything else.

Of course, if you use the twistd daemon installing a specific reactor at
the correct time is easy, by using the --reactor flag.


- Matt





More information about the Twisted-Python mailing list