Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: mojo/public/python/mojo/system.pyx

Issue 552783004: mojo: Add a runloop utility in python (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/python/mojo/system.pyx
diff --git a/mojo/public/python/mojo/system.pyx b/mojo/public/python/mojo/system.pyx
index bd0355032a5883f1856e7d7b08d82dffb4e4f431..381c35fbe15765a974ee72ec940a3a124602377b 100644
--- a/mojo/public/python/mojo/system.pyx
+++ b/mojo/public/python/mojo/system.pyx
@@ -5,6 +5,8 @@
# distutils language = c++
cimport c_core
+cimport c_environment
+
from cpython.buffer cimport PyBUF_CONTIG
from cpython.buffer cimport PyBUF_CONTIG_RO
@@ -694,3 +696,32 @@ class DuplicateSharedBufferOptions(object):
def __init__(self):
self.flags = DuplicateSharedBufferOptions.FLAG_NONE
+
+
+cdef class RunLoop(object):
+ """RunLoop to use when using asynchronous operations on handles."""
+
+ cdef c_environment.CRunLoop c_run_loop
+
+ def Run(self):
+ """Run the runloop until Quit is called."""
+ self.c_run_loop.Run()
+
+ def RunUntilIdle(self):
+ """Run the runloop until Quit is called or no operation is waiting."""
+ self.c_run_loop.RunUntilIdle()
+
+ def Quit(self):
+ """Quit the runloop."""
+ self.c_run_loop.Quit()
+
+ def PostDelayedTask(self, runnable, delay=0):
+ """
+ Post a task on the runloop. This must be called from the thread owning the
+ runloop.
+ """
+ cdef c_environment.CClosure closure = c_environment.BuildClosure(runnable)
+ self.c_run_loop.PostDelayedTask(closure, delay)
+
+
+c_environment.InitRunLoop()

Powered by Google App Engine
This is Rietveld 408576698