Permalink
Browse files

clock: add an admonition about the Clock / weakref. closes #545

  • Loading branch information...
1 parent f632178 commit e0a2a390a4e70a826d14fd300abfa0065c18f67e @tito tito committed Jun 29, 2012
Showing with 26 additions and 0 deletions.
  1. +26 −0 kivy/clock.py
View
@@ -33,6 +33,32 @@ def my_callback(value, key, *largs):
Clock.schedule_interval(partial(my_callback, 'my value', 'my key'), 0.5)
+.. important::
+
+ The callback is weak-referenced: you are responsible to keep a reference to
+ your original object/callback. If you don't keep a reference, the Clock will
+ never execute your callback. For example::
+
+ class Foo(object):
+ def start(self):
+ Clock.schedule_interval(self.callback)
+
+ def callback(self, dt):
+ print 'In callback'
+
+ # a Foo object is created, the method start is called,
+ # and the instance of foo is deleted
+ # Because nobody keep a reference to the instance returned from Foo(),
+ # the object will be collected by Python Garbage Collector. And you're
+ # callback will be never called.
+ Foo().start()
+
+ # So you must do:
+ foo = Foo()
+ foo.start()
+
+ # and keep the instance of foo, until you don't need it anymore!
+
Schedule before frame
---------------------

0 comments on commit e0a2a39

Please sign in to comment.