Kivy: L'utilisation de twisted, kivy et pyinstaller génère une erreur.ReactorAlreadyInstalledError ("réacteur déjà installé")

Créé le 17 avr. 2016  ·  7Commentaires  ·  Source: kivy/kivy

fichier_spéc

c:\Users\sony\Dropbox\notepad_app\2_Paint\build_windows>cat noteapp.spec
# -*- mode: python -*-

block_cipher = None


a = Analysis(['..\\__main__.py'],
             pathex=['c:\\Users\\sony\\Dropbox\\notepad_app\\2_Paint\\build_windows'],
             binaries=None,
             datas=None,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='noteapp',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='noteapp')

exécutable en cours d'exécution

La première ligne imprime tous les modules chargés jusqu'à présent. Pour vérifier si le réacteur torsadé est chargé avant from kivy.support import install_twisted_reactor

c:\Users\sony\Dropbox\notepad_app\2_Paint\build_windows\dist\noteapp>cmd /K noteapp.exe
[<module 'pyimod03_importers' from 'c:\python27\lib\site-packages\PyInstaller-3.2.dev0+g2f86ac6-py2.7.egg\PyInstaller\loader\pyimod03_importers.py'>, <module 'tempfile' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\tempfile.pyc'>, <module 'sys' (built-in)>, <module 'atexit' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\atexit.pyc'>, <module 'ctypes' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\ctypes\__init__.pyc'>, <module 'encodings' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\encodings\__init__.pyc'>, <module 'win32com' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\win32com\__init__.pyc'>, <module 'shutil' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\shutil.pyc'>, <module 'os' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\os.pyc'>]
[INFO              ] [Logger      ] Record log in c:/Users/sony\.kivy\logs\kivy_16-04-17_2.txt
[INFO              ] [Kivy        ] v1.9.2-dev0
[INFO              ] [Python      ] v2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)]
 Traceback (most recent call last):
   File "c:\Users\sony\Dropbox\notepad_app\2_Paint\__main__.py", line 7, in <module>
     install_twisted_reactor() # twisted eventloop with kivy on the same reactor
   File "c:\python27\lib\site-packages\kivy\support.py", line 176, in install_twisted_reactor
     _threadedselect.install()
   File "c:\Python27\lib\site-packages\twisted\internet\_threadedselect.py", line 354, in install
     installReactor(reactor)
   File "c:\Python27\lib\site-packages\twisted\internet\main.py", line 32, in installReactor
     raise error.ReactorAlreadyInstalledError("reactor already installed")
 twisted.internet.error.ReactorAlreadyInstalledError: reactor already installed
Failed to execute script __main__

.py principal

#Written according to https://kivy.org/docs/guide/other-frameworks.html
#works fine when using python __main__.py
import sys
modulenames = set(sys.modules)&set(globals())
allmodules = [sys.modules[name] for name in modulenames]
print allmodules
#reactor import (compulsory first import)
from kivy.support import install_twisted_reactor
install_twisted_reactor() # twisted eventloop with kivy on the same reactor
#kivy import
from kivy.app import App
from kivy.config import Config
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.lang import Builder
#twisted and other-control imports
from twisted.internet import reactor
#screens and widgets imports
from screens.login_screen import LoginScreen
from canvas.canvas_widget import CanvasWidget,RadioButton
from screens.approve_clients import ApproveClients
#server and behaviour configuration file import
from config import config
try:
    import _cffi_backend
except:
    print "Please install PyInstaller for building. Not necessary for running."
#adding twisted imports
from twisted.internet.defer import DeferredQueue
from twisted.internet.protocol import ClientFactory
from twisted.protocols.basic import NetstringReceiver
from twisted.internet import defer
from twisted.protocols.basic import NetstringReceiver
from twisted.internet.defer import inlineCallbacks
from twisted.internet.threads import deferToThread
from twisted.internet.protocol import ClientFactory
import os
###############################################
#Screen specified below have majority behaviour specified in .kv
#Other screens are sin ./screens
class ActivitySelectScreen(Screen):
    '''allows user to choose whether to 
            1. create server 
            2. connect to a pre-existing one '''
    def __init__(self,**kwargs):
        super(ActivitySelectScreen, self).__init__(**kwargs)


class PaintApp(Screen):
    '''Screen class of the canvas widget'''
    def __init__(self,**kwargs):
        super(PaintApp, self).__init__(**kwargs)

class AppScreenManager(ScreenManager):
    '''ScreenManager class'''

class notepad_app_v0(App):
    '''Base application class'''
    def build(self):
        self.reactor=reactor
        self.config_obj=config(allow_all=False,debug=False,activate_audio=True)
        return Builder.load_file('.'+os.sep+'kivy'+os.sep+'paint.kv')

if __name__ == '__main__':
    #setting resolution
    Config.set('graphics', 'width', '960')
    Config.set('graphics', 'height', '540')  # 16:9
    #disabling multi-touch and resizing the app
    Config.set('graphics', 'resizable', '0')
    Config.set('input', 'mouse', 'mouse,disable_multitouch')
    notepad_app_v0().run()

Commentaire le plus utile

Dans l'exécutable créé par pyinstaller twisted.internet.reactor semble être initialisé avant l'exécution du code kivy réel (quoi que ce soit). Comme solution de contournement, vous pouvez faire :

import kivy
kivy.require('1.9.1')

# fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
import sys
if 'twisted.internet.reactor' in sys.modules:
    del sys.modules['twisted.internet.reactor']

# install twisted reactor
from kivy.support import install_twisted_reactor
install_twisted_reactor()

Tous les 7 commentaires

Une mise à jour sur ce problème ou une résolution par quelqu'un?

Dans l'exécutable créé par pyinstaller twisted.internet.reactor semble être initialisé avant l'exécution du code kivy réel (quoi que ce soit). Comme solution de contournement, vous pouvez faire :

import kivy
kivy.require('1.9.1')

# fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
import sys
if 'twisted.internet.reactor' in sys.modules:
    del sys.modules['twisted.internet.reactor']

# install twisted reactor
from kivy.support import install_twisted_reactor
install_twisted_reactor()

peut-être que la solution de contournement devrait faire partie de kivy.support.install_twisted_reactor ?

Ce problème a été automatiquement marqué comme obsolète car il n'a pas eu d'activité récente. Il sera fermé si aucune autre activité ne se produit. Merci pour vos contributions.

Nous avons besoin d'un moyen de contourner la sélection du réacteur OU même de permettre un moyen d'ignorer complètement le crochet tordu. Existe-t-il actuellement un moyen de faire tout cela ?

Le même problème se produit lors de l'utilisation de PyInstaller qt5 et Twisted avec le qt5reactor personnalisé.
La solution de contournement de rnixx résout le problème.
Merci

# fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
import sys
if 'twisted.internet.reactor' in sys.modules:
    del sys.modules['twisted.internet.reactor']

from PySide2.QtWidgets import QApplication
app = QApplication(sys.argv) 
import qt5reactor
qt5reactor.install()

PS : Désolé d'avoir publié une solution liée à qt dans un fil de discussion lié à Kivy. Pourtant, ce ReactorAlreadyInstalledError semble être un problème général du crochet torsadé lors de l'utilisation de différents réacteurs

Merci de l'avoir ramené, mais ce n'est pas du tout la faute de Kivy. Consultez https://github.com/pyinstaller/pyinstaller/issues/3390 - Il s'agit d'un problème générique sur pyinstaller avec leur crochet d'exécution qui installe un réacteur torsadé avant que vous ne puissiez réellement le sélectionner.

Cette page vous a été utile?
0 / 5 - 0 notes