Commits

Ronny Pfannschmidt  committed a7f6592

i can sleep

  • Participants

Comments (0)

Files changed (2)

+import glib, gtk
+
+class GtkLoop(object):
+    def __init__(self, flags=None, default=True):
+        assert default
+
+
+    def timer(self, after, repeat=0):
+        return timer(self, after, repeat)
+
+    def run(self):
+        gtk.main()
+
+
+class timer(object):
+    def __init__(self, loop, after, repeat=0):
+        self.loop = loop
+        self.after = after
+        self.repeat = repeat
+        self.source_id = None
+
+    def first_callback(self):
+        try:
+            self.callback(*self.args)
+        except:
+            self.loop.handle_error(callback, *sys.exc_info())
+        return False
+
+
+    def start(self, callback, *args):
+        self.callback = callback
+        self.args=args
+
+
+        self.source_id = glib.timeout_add(
+            self.after*1000,
+            self.first_callback)
+
+    def stop(self):
+        #XXX: check this never raises
+        glib.source_remove(self.source_id)
+

File somescript.py

+
+
+from gtkloop import GtkLoop
+from gevent.hub import Hub
+
+Hub.loop_class = GtkLoop
+
+
+import gevent
+gevent.sleep(3)