[Twisted-Python] Error "reactor already installed" - exact module import order?

Hi everyone, I would be grateful if someone could help me with the error "reactor already installed". I have seen this issue has been discussed previously, but I am not sure how to fix appropriate file so that error does not occur anymore. I am using Twisted Python 2.4.0, as it is packaged by Mandriva. Here is the Python stack trace: ----------------- cut 8< ------------------- Traceback (most recent call last): File "/usr/bin/pyscrabble.py", line 4, in ? gtk2reactor.install() File "/usr/lib/python2.4/site-packages/twisted/internet/gtk2reactor.py", line 270, in install installReactor(reactor) File "/usr/lib/python2.4/site-packages/twisted/internet/main.py", line 23, in installReactor assert not sys.modules.has_key('twisted.internet.reactor'), \ AssertionError: reactor already installed ----------------- cut 8< ------------------- Here is the piece of code that causes error: ----------------- /usr/bin/pyscrabble.py ------------------- #!/usr/bin/env python from twisted.internet import gtk2reactor gtk2reactor.install() ... ----------------- /usr/bin/pyscrabble.py ------------------- As for the "pyscrabble.py" causing, I'll contact its author, but is it possible to change ".../twisted/internet/main.py" so that it does not throw assertion error on already installed reactor? Many thanks in advance, Zoltan

On Sun, 29 Oct 2006 02:37:22 +0200, "Zoltan \(Twisted Python Mailing List\)" <twisted-matrix@mail11.ml1.net> wrote:
Hi everyone,
Hello.
This happens when an attempt is made to install more than one reactor in a single process. Twisted supports only a single reactor. When twisted.internet.reactor is imported for the very first time, if no other reactor has been installed, the default reactor is installed. If any other reactor has been installed, that reactor is given back as the result of the import.
This seems strange. Since only one reactor is being installed here, the traceback above should not be happening. I cannot replicate this failure; when I try the above script, it works as expected (producing no output). Do you have something in your environment which might be causing some other reactor to be installed, or for twisted.internet.reactor to be imported, causing the default reactor to be installed? For example, do you have a sitecustomize.py which is doing something with Twisted?
It's possible to make that change (by editing the source of Twisted), but it seems unlikely that just suppressing the exception will solve the problem. Jean-Paul

On Sun, 29 Oct 2006 02:37:22 +0200, "Zoltan \(Twisted Python Mailing List\)" <twisted-matrix@mail11.ml1.net> wrote:
Hi everyone,
Hello.
This happens when an attempt is made to install more than one reactor in a single process. Twisted supports only a single reactor. When twisted.internet.reactor is imported for the very first time, if no other reactor has been installed, the default reactor is installed. If any other reactor has been installed, that reactor is given back as the result of the import.
This seems strange. Since only one reactor is being installed here, the traceback above should not be happening. I cannot replicate this failure; when I try the above script, it works as expected (producing no output). Do you have something in your environment which might be causing some other reactor to be installed, or for twisted.internet.reactor to be imported, causing the default reactor to be installed? For example, do you have a sitecustomize.py which is doing something with Twisted?
It's possible to make that change (by editing the source of Twisted), but it seems unlikely that just suppressing the exception will solve the problem. Jean-Paul
participants (2)
-
Jean-Paul Calderone
-
Zoltan (Twisted Python Mailing List)