Created
September 29, 2019 11:46
-
-
Save gottadiveintopython/93e234d3af0de44ed5730e920e6d8a8b to your computer and use it in GitHub Desktop.
"Animation._instances" keeps getting fat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| https://youtu.be/P2WtjZAWc8I | |
| ''' | |
| from kivy.app import App | |
| from kivy.factory import Factory | |
| from kivy.animation import Animation | |
| from kivy.clock import Clock | |
| import itertools | |
| anim_id_iter = itertools.count() | |
| def start_new_animation(dt): | |
| print("len(Animation._instances) ==", len(Animation._instances)) | |
| print(f"start {next(anim_id_iter)}th animation") | |
| w = Factory.Widget() | |
| anim1 = Animation(x=100) | |
| anim2 = Animation(y=200) | |
| (anim1 & anim2).start(w) | |
| Clock.schedule_once(lambda dt: anim1.cancel(w), .5) | |
| class SampleApp(App): | |
| def build(self): | |
| return Factory.Widget() | |
| def on_start(self): | |
| Clock.schedule_interval(start_new_animation, 1) | |
| SampleApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment