0

I'm trying to play around with a real-time kivy graph using the kivy_garden.graph module. However, when i run the following code, I get no error message other than a popup stating 'Python has stopped working'. Once I press cancel on that, I get Process finished with exit code -1073741819 (0xC0000005). Here's my code:

from math import sin
from kivy_garden.graph import Graph, MeshLinePlot
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock


class MyApp(App):
    plot = MeshLinePlot(color=[1, 0, 0, 1])

    graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5,
        x_ticks_major=25, y_ticks_major=1,
        y_grid_label=False, x_grid_label=False, padding=5,
        x_grid=False, y_grid=False, xmin=-0, xmax=100, ymin=-1, ymax=1,)

    def build(self):

        box = BoxLayout()
        box.add_widget(self.graph)
        Clock.schedule_interval(self.update_points, 1/60.)
        Clock.schedule_interval(self.update_xaxis, 1/60.)

        return box

    def update_xaxis(self,*args):
        self.graph.xmin = 0
        self.graph.xmax = 100

    def update_points(self, *args):
        #self.plot.points = [(i,i)]

        self.plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]





MyApp().run()

My other kivy apps are running just fine on the same python installation, so I'm inclined to believe that there's something wrong with my code.

Thanks for any and all help!

2 Answers2

2

Strange as it may seem, it appears that your Graph() and MeshLinePlot() calls must be in the opposite order:

class MyApp(App):
    graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5,
        x_ticks_major=25, y_ticks_major=1,
        y_grid_label=False, x_grid_label=False, padding=5,
        x_grid=False, y_grid=False, xmin=-0, xmax=100, ymin=-1, ymax=1,)
    plot = MeshLinePlot(color=[1, 0, 0, 1])

    def build(self):
        self.graph.add_plot(self.plot)
        box = BoxLayout()
        box.add_widget(self.graph)
        Clock.schedule_interval(self.update_points, 1/60.)
        Clock.schedule_interval(self.update_xaxis, 1/60.)

        return box

And you were missing the self.graph.add_plot(self.plot) line.

John Anderson
  • 35,991
  • 4
  • 13
  • 36
0

Research

The error-code 0xC0000005 might be a Windows related error, known as Access Violation. See Process finished with exit code -1073741819 (0xC0000005) Pycharm

On the other side any threading-related seems suspicious. So, searched for Clock.schedule_interval and found an answer that suggested to avoid duplicate scheduling. See Kivy - Trying to Understand Clock.schedule_interval.

To avoid duplicate calls, they propose to unschedule before scheduling again.

# First, schedule once.
event = Clock.schedule_once(my_callback, 0)

# Then, in another place you will have to unschedule first to avoid duplicate call. Then you can schedule again.
Clock.unschedule(event)
event = Clock.schedule_once(my_callback, 0)

I can't tell what your separately scheduled update-events are for, but it looks like they can be combined to one update-callback.

hc_dev
  • 8,389
  • 1
  • 26
  • 38