1

Setup

  • Kivy 1.11.1
  • Flask 1.1.1
  • Python 2.7.13

Issue

I have an issue running together a Kivy app and Flask as thread on a RPi2 with a touchscreen. It is similar to the issue mentioned in this post Issues with Kivy on Raspberry Pi 3 with 3.5 in Touchscreen with the difference the touch screen works when running the Kivy app only with no Flask in the background. The Kivy+Flask app for the touch screen works on my notebook but when launching it on the RPi2, just hangs forever. No window pops up, nothing.

To exit I have to continuously press CTRL+C and the app loads step by step till finally launch the Kivy app of the touch as supposed.

As one reason I have checked the input interface issue mentioned in this post but I guess does not apply to my case.

UPDATE -> Output of the notebook:

[INFO   ] [Base        ] Leaving application in progress...
(py2) parovelb@Latitude-E6510:~/Desktop/Python2$ python cs_flask_tft_20191219.py 
[INFO   ] [Logger      ] Record log in /home/parovelb/.kivy/logs/kivy_19-12-19_1.txt
[INFO   ] [Kivy        ] v1.10.1
[INFO   ] [Python      ] v2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
Starting Flask app...
 (20301) wsgi starting up on http://0.0.0.0:5000
[INFO   ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <gl>
[INFO   ] [GL          ] OpenGL version <3.3 (Compatibility Profile) Mesa 19.0.8>
[INFO   ] [GL          ] OpenGL vendor <nouveau>
[INFO   ] [GL          ] OpenGL renderer <NVA8>
[INFO   ] [GL          ] OpenGL parsed version: 3, 3
[INFO   ] [GL          ] Shading version <3.30>
[INFO   ] [GL          ] Texture max size <8192>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available

Output of the RPi2:

[INFO   ] [Logger      ] Record log in /home/pi/.kivy/logs/kivy_19-12-19_5.txt
[INFO   ] [Kivy        ] v1.11.1
[INFO   ] [Kivy        ] Installed at "/home/pi/.virtualenvs/py2/local/lib/python2.7/site-packages/kivy/__init__.pyc"
[INFO   ] [Python      ] v2.7.13 (default, Sep 26 2018, 18:42:22) 
[GCC 6.3.0 20170516]
[INFO   ] [Python      ] Interpreter at "/home/pi/.virtualenvs/py2/bin/python"
[WARNING] [Deprecated  ] Python 2 Kivy support has been deprecated. The Kivy release after 1.11.0 will not support Python 2 anymore
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_pil, img_gif (img_sdl2, img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2(['text_pango'] ignored)
Starting Flask app...
 (2950) wsgi starting up on http://0.0.0.0:5000
[INFO   ] [Window      ] Provider: egl_rpi
[INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
[INFO   ] [GL          ] Backend used <gl>
[INFO   ] [GL          ] OpenGL version <OpenGL ES 2.0>
[INFO   ] [GL          ] OpenGL vendor <Broadcom>
[INFO   ] [GL          ] OpenGL renderer <VideoCore IV HW>
[INFO   ] [GL          ] OpenGL parsed version: 2, 0
[INFO   ] [GL          ] Shading version <OpenGL ES GLSL ES 1.00>
[INFO   ] [GL          ] Texture max size <2048>
[INFO   ] [GL          ] Texture max units <8>
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event5
[INFO   ] [MTD         ] Read event from </dev/input/event5>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event3
[INFO   ] [MTD         ] Read event from </dev/input/event3>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event1
[INFO   ] [MTD         ] Read event from </dev/input/event1>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event4
[INFO   ] [MTD         ] Read event from </dev/input/event4>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event2
[INFO   ] [MTD         ] Read event from </dev/input/event2>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event0
[INFO   ] [MTD         ] Read event from </dev/input/event0>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event5
[INFO   ] [HIDInput    ] Read event from </dev/input/event5>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event3
[INFO   ] [HIDInput    ] Read event from </dev/input/event3>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event1
[INFO   ] [HIDInput    ] Read event from </dev/input/event1>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event4
[INFO   ] [HIDInput    ] Read event from </dev/input/event4>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event2
[INFO   ] [HIDInput    ] Read event from </dev/input/event2>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event0
[INFO   ] [HIDInput    ] Read event from </dev/input/event0>
[INFO   ] [Base        ] Start application main loop
[INFO   ] [MTD         ] </dev/input/event5> range position X is 0 - 0
[INFO   ] [MTD         ] </dev/input/event5> range position Y is 0 - 0
[INFO   ] [MTD         ] </dev/input/event5> range touch major is 0 - 0
[INFO   ] [MTD         ] </dev/input/event5> range touch minor is 0 - 0
[INFO   ] [MTD         ] </dev/input/event5> range pressure is 0 - 255
[INFO   ] [MTD         ] </dev/input/event5> axes invertion: X is 0, Y is 0
[INFO   ] [MTD         ] </dev/input/event5> rotation set to 0

Any ideas? GIL?

2 Answers 2

1

I did a fresh install of Kivy and rewrote the code step by step to find the issue. The reason why the Kivy app hanging forever was the line:

eventlet.monkey_patch()

Once commented out Kivy was up and running with Flask in parallel.

2
  • Please accept one of your own answers with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year.
    – Ingo
    Commented Feb 7, 2020 at 18:30
  • @Ingo, thank you for the hint. I was looking for a way on how to close an open issue for some time.
    – parovelb
    Commented Feb 11, 2020 at 13:45
0

This is not a direct answer to the Flask blocking Kivy and vice versa issue but is an alternative solution. I gave it a try with process and seems it does the work. Hope it helps.

CODE

#!/usr/bin/python2.7 python2.7
# -*- coding: utf-8 -*-

# kivy modules first, if not Kivy may cause problems
import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.screenmanager import ScreenManager, Screen
kivy.require('1.10.0')


# common modules
import sys
import signal
from multiprocessing import Process


# Flask & similar modules
from flask import Flask
from flask_restful import reqparse, abort, Api, Resource
import eventlet
from eventlet import wsgi


# async server setup
eventlet.monkey_patch()
app = Flask(__name__)
api = Api(app)


def start_Flask():
    print("Starting Flask...")
    # deploy as an eventlet WSGI server on port 5000
    wsgi.server(eventlet.listen(('', 5000)), app)     


def signal_handler(signal, frame):
    # for fetching CTRL+C and relatives
    print " CTRL + C detected, exiting ... "
    exit(1)


# Kivy screen class
class MainScreen(Screen):
    def __init__(self, **kwargs):
        self.name="MAIN SCREEN"
        super(Screen, self).__init__(**kwargs)


# Kivy app class
class Kivy(App):
    w_MessageBox10_1 = "MAIN SCREEN"
    w_MessageBox10_2 = "One golden glance of what should be"
    w_MessageBox30_2 = "CHORUS"
    w_MessageBox30_3 = "EXIT"


    # exit button action   
    def exit(self):
        print "exiting... one shaft of light will show the way..."
        p1.terminate()  # terminate Flask by pressing on cancel
        exit(1)


    # do magic button action
    def do_magic(self):
        # your code goes here or maybe not
        print "***** it's a kind of magic *************************"


    # Kivy UI builder file
    def build(self):
        sm = Builder.load_string("""

ScreenManager
    MainScreen:
        size_hint: 1, .7
        auto_dismiss: False
        title: app.w_MessageBox10_1       
        title_align: "center"

        BoxLayout:
            orientation: "vertical"
            Label:
                text: app.w_MessageBox10_2
            BoxLayout:
                orientation: "horizontal"
                spacing: 10
                size_hint: 1, .5
                Button:
                    text: app.w_MessageBox30_2  # DO MAGIC
                    on_press:
                        app.do_magic()
                Button:
                    text: app.w_MessageBox30_3  # EXIT
                    on_press:
                        app.exit()


        """)

        return sm


if __name__ == '__main__':    

    # #CTRL+C signal handler
    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    global p1
    p1 = Process(target=start_Flask)    # assign Flask to a process
    p1.start()                          # run Flask as process
    Kivy().run()                        # run Kivy UI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.