[Twisted-Python] How can I make twisted and dbus work together?
Matt Goodall
matt at pollenation.net
Wed Jan 16 06:28:09 EST 2008
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.)
- Matt
--
Matt Goodall
Technical Director, Pollenation Internet Ltd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lazy-reactor-import.patch
Type: text/x-patch
Size: 1070 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20080116/2f6ce7c4/attachment.bin
More information about the Twisted-Python
mailing list