How can I profile a Kivy application?

2024/9/8 10:02:46

I'm building a game using Kivy. I'm encountering performance issues so I decided to profile the program.

I tried to run it by:

python -m cProfile main.py

The application screen stays black. After several seconds, an exception crashes the program:

 Traceback (most recent call last):File "c:\python27\Lib\runpy.py", line 162, in _run_module_as_main"__main__", fname, loader, pkg_name)File "c:\python27\Lib\runpy.py", line 72, in _run_codeexec code in run_globalsFile "c:\python27\Lib\cProfile.py", line 199, in <module>main()File "c:\python27\Lib\cProfile.py", line 192, in mainrunctx(code, globs, None, options.outfile, options.sort)File "c:\python27\Lib\cProfile.py", line 49, in runctxprof = prof.runctx(statement, globals, locals)File "c:\python27\Lib\cProfile.py", line 140, in runctxexec cmd in globals, localsFile "main.py", line 26, in <module>GameApp().run()File "C:\Users\Aviv\Envs\game\lib\site-packages\kivy\app.py", line 828, in runrunTouchApp()File "C:\Users\Aviv\Envs\game\lib\site-packages\kivy\base.py", line 487, in runTouchAppEventLoop.window.mainloop()File "C:\Users\Aviv\Envs\game\lib\site-packages\kivy\core\window\window_sdl2.py", line 619, in mainloopself._mainloop()File "C:\Users\Aviv\Envs\game\lib\site-packages\kivy\core\window\window_sdl2.py", line 403, in _mainloopx, y = self._fix_mouse_pos(x, y)File "C:\Users\Aviv\Envs\game\lib\site-packages\kivy\core\window\window_sdl2.py", line 358, in _fix_mouse_posself.mouse_pos = x, self.system_size[1] - yFile "kivy\properties.pyx", line 408, in kivy.properties.Property.__set__ (kivy\properties.c:5114)File "kivy\properties.pyx", line 446, in kivy.properties.Property.set (kivy\properties.c:5876)File "kivy\properties.pyx", line 501, in kivy.properties.Property.dispatch (kivy\properties.c:6557)File "kivy\_event.pyx", line 1224, in kivy._event.EventObservers.dispatch (kivy\_event.c:13497)File "kivy\_event.pyx", line 1130, in kivy._event.EventObservers._dispatch (kivy\_event.c:12696)File "game\opening_screen.py", line 22, in _on_mouse_posif self.ids.start_button.collide_point(*position):File "kivy\properties.pyx", line 757, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:11882)AttributeError: 'super' object has no attribute '__getattr__'

Why is this happening, and how can I profile my Kivy application?

Answer

The kivy docs state that you cannot do it from the command line.

https://kivy.org/docs/api-kivy.app.html

You can do it like this: (copied from the docs)

import cProfileclass MyApp(App):def on_start(self):self.profile = cProfile.Profile()self.profile.enable()def on_stop(self):self.profile.disable()self.profile.dump_stats('myapp.profile')
https://en.xdnf.cn/q/72814.html

Related Q&A

Set up multiple python installations on windows with tox

I am trying to set up tox on windows to run tests against multiple python installations. I have installed each python in folders named, C:\Python\PythonXX_YY, XX is the python version (e.g. 27) and YY…

How can I change the alpha value dynamically in matplotlib python

Im seeking how to change an alpha value dynamically which are already plotted.This is a kind of sample code I want to implement, but I know it is a wrong writing.import matplotlib.pyplot as pltfig = pl…

How to detect write failure in asyncio?

As a simple example, consider the network equivalent of /dev/zero, below. (Or more realistically, just a web server sending a large file.)If a client disconnects early, you get a barrage of log message…

how to get place details from place id in google places api for python

I am using the Google Places API with Python to build a collective intelligence app for food. e.g. what restaurants are around, what ratings they have, what are their timings, etc.I am doing the follow…

pandas.algos._return_false causes PicklingError with dill.dump_session on CentOS

I have a code framework which involves dumping sessions with dill. This used to work just fine, until I started to use pandas. The following code raises a PicklingError on CentOS release 6.5:import pan…

How to send an image directly from flask server to html?

I am new to flask and am trying to make an app such an image is taken by the html and js from the webcam and then it is sent to the server with ajax request. I got this part. Then some processing is do…

Alternatives to nested numpy.where for multiconditional pandas operations?

I have a Pandas DataFrame with conditional column A and numeric column B. A B 1 foo 1.2 2 bar 1.3 3 foo 2.2I also have a Python dictionary that defines ranges of B which denote "success" g…

OpenCV findContours() just returning one external contour

Im trying to isolate letters in a captcha, I managed to filter a captcha and that result in this black and white image:But when I tried to separate the letters with findContours method of OpenCV it jus…

Selenium/ChromeDriver Unknown policy Errors

I am currently using Python (v3.5.1), Selenium (v3.7), and Chromedriver (v2.33).When I run the following command:from selenium import webdriver driver = webdriver.Chrome(C:\Program Files\ChromeWebdrive…

Mako escaping issue within Pyramid

I need to put javascript function to mako template. The first argument of this function is string, so I write in my *.mako file (dict(field_name=geom)):init_map(${field_name} );But when I see my html p…