qt4reactor.install() causing Assertion failure in latest pyinstaller

326 views
Skip to first unread message

Abhishek Ranjan

unread,
Aug 1, 2013, 11:19:26 AM8/1/13
to pyins...@googlegroups.com
Hi,
I have been using Pyinstaller to package an application which uses twisted as well as Qt. Upto version 2.0.0 the installer has been getting generated fine, but recently I updated the pyinstaller with the latest on github - 2.1.0 and now the application doesn't start. I noticed that it fails at the point where qt4reactor.install is called. I tried it on a small snippet of code -
 
test.py
 
from twisted.internet import protocol
from PyQt4.QtGui import QApplication
import qt4reactor
app = QApplication([])
qt4reactor.install()
print "Qt4 reactor installed"
and used the following command to generate the installer -
pyinstaller pyinstaller.py --onedir test.py
 
With version 2.0.0 the executable works fine, but with the new pyinstaller (2.1.0), I see this error -
 
build\pyinstaller\test>.\dist\test\test.exe
win32install 1
win32install 2
Traceback (most recent call last):
  File "<string>", line 5, in <module>
  File "C:\Users\user_3\blib-rel\blib\build\pyinstaller\test\build\test\out00-PY
Z.pyz\qt4reactor", line 349, in win32install
  File "C:\Users\user_3\blib-rel\blib\build\pyinstaller\test\build\test\out00-PY
Z.pyz\twisted.internet.main", line 32, in installReactor
twisted.internet.error.ReactorAlreadyInstalledError: reactor already installed
^C
C:\Users\user_3\blib-rel\blib\build\pyinstaller\test>python ..\pyinstaller.py --
onedir test.py
 
Is this a known issue ?  Is there a work around for this ?
 
I need to use version 2.1.0 because of a PIL rthook related fix which went  in, in that version (http://www.pyinstaller.org/ticket/651)
 
Thanks,
Abhishek.
 

Martin Zibricky

unread,
Aug 1, 2013, 1:47:56 PM8/1/13
to pyins...@googlegroups.com
Abhishek Ranjan píše v Čt 01. 08. 2013 v 08:19 -0700:
> Is this a known issue ? Is there a work around for this ?

There is an rt-hook for twisted that sets the default reactor and thus
you get this msg 'reactor already installed'.

You could try to uninstall the default reactor in your code or remove
the rt_hook.


Do you have suggestion how to solve this in pyinstaller in general? We
could:

1) remove the twisted rt_hook and provide instructions how to set the
default reactor or
2) keep rt_hook and provide instructions how to get working custom
reactor.

Which way would you prefer as the default solution in pyinstaller?


Abhishek Ranjan

unread,
Aug 2, 2013, 1:24:45 PM8/2/13
to pyins...@googlegroups.com
Thanks Martin for your quick reply and sorry for my delayed reply ! 
For me removing the default reactor from rt-hook made it work but I could not uninstall the default reactor. selectReactor in twisted only seems to expose the installReactor function. 
With that being the case, I would vote for a solution where I don't have to modify the pyinstaller code to make it work for my code even if that means making slight changes to my code.  So, I would prefer to have the solution 1 as default. 

what instructions would you be providing for option 2 ? Will it be to remove the rt hook or something else? 


Thanks,
Abhishek.

Martin Zibricky

unread,
Aug 2, 2013, 2:49:10 PM8/2/13
to pyins...@googlegroups.com
Abhishek Ranjan píše v Pá 02. 08. 2013 v 10:24 -0700:
> Thanks Martin for your quick reply and sorry for my delayed reply !
> For me removing the default reactor from rt-hook made it work but I
> could not uninstall the default reactor. selectReactor in twisted only
> seems to expose the installReactor function.
> With that being the case, I would vote for a solution where I don't
> have to modify the pyinstaller code to make it work for my code even
> if that means making slight changes to my code. So, I would prefer to
> have the solution 1 as default.
>
>
> what instructions would you be providing for option 2 ? Will it be to
> remove the rt hook or something else?

We need to find out something for the option 2.


Martin Zibricky

unread,
Aug 2, 2013, 2:59:47 PM8/2/13
to pyins...@googlegroups.com
Abhishek Ranjan píše v Pá 02. 08. 2013 v 10:24 -0700:
> what instructions would you be providing for option 2 ? Will it be to
> remove the rt hook or something else?

Could you try in your app code like this?


import sys
del sys.modules['twisted.internet.reactor']
import qt4reactor
qt4reactor.install()

Abhishek Ranjan

unread,
Aug 2, 2013, 11:41:20 PM8/2/13
to pyins...@googlegroups.com
Hi Martin,
This works in the code snippet properly, not yet in my application (which I will need to debug) as it has multiple processes.
Thanks,
Abhishek.

Abhishek Ranjan

unread,
Aug 3, 2013, 12:42:37 AM8/3/13
to pyins...@googlegroups.com
This worked for my application as well.
 
Thanks a lot !
Abhishek.
 

On Thursday, August 1, 2013 8:19:26 AM UTC-7, Abhishek Ranjan wrote:

Patrick Bug

unread,
Jun 22, 2014, 6:12:11 PM6/22/14
to pyins...@googlegroups.com
import sys 
del sys.modules['twisted.internet.reactor'] 
import qt4reactor 
qt4reactor.install() 

When I use this with pyinstaller, compiling and executing the .exe file works fine. Problem is that my GUI application is not exiting properly when a user hits the Close-button of the window.
The console window remains open and is idling. When compiled without console window enabled, the process remains until closed via task manager.

Burak Nehbit

unread,
Jun 23, 2014, 6:35:57 PM6/23/14
to pyins...@googlegroups.com
I have a similar issue with qtreactor (for qt5), but in OS X. The application works fine from clicking the executable itself, with command line, but it completely fails to open when the user tries to open it as an .app bundle, which is the normal way OS X programs are run. I have found no solutions either.


--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To post to this group, send email to pyins...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyinstaller.
For more options, visit https://groups.google.com/d/optout.

Stephen Waterbury

unread,
Aug 9, 2021, 4:38:41 AM8/9/21
to PyInstaller
Although the original thread is 6 years old, this problem with the twisted hook persists.
Monkey-patching the hook works (comment out the content of the hook), but that
is obviously undesirable.

Is there any new thinking on a solution?
Reply all
Reply to author
Forward
0 new messages