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

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: Do not acquire GIL when called from python. 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
« no previous file with comments | « mojo/public/python/mojo/c_environment.pxd ('k') | mojo/public/python/src/python_system_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..84fbfefef716e78b90a8f54b3774f53c2234bee3 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)
+
+
+cdef c_environment.CEnvironment* _ENVIRONMENT = new c_environment.CEnvironment()
« no previous file with comments | « mojo/public/python/mojo/c_environment.pxd ('k') | mojo/public/python/src/python_system_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698