Commits

Denis Bilenko  committed 7a40b4b

core: all watchers (except for child) now accept 'priority' argument to contrustructor

  • Participants
  • Parent commits 6afaa8d

Comments (0)

Files changed (1)

File gevent/core.ppyx

                     return value
             return backend
 
-    def io(self, int fd, int events, ref=True):
-        return io(self, fd, events, ref)
+    def io(self, int fd, int events, ref=True, priority=None):
+        return io(self, fd, events, ref, priority)
 
-    def timer(self, double after, double repeat=0.0, ref=True):
-        return timer(self, after, repeat, ref)
+    def timer(self, double after, double repeat=0.0, ref=True, priority=None):
+        return timer(self, after, repeat, ref, priority)
 
-    def signal(self, int signum, ref=True):
-        return signal(self, signum, ref)
+    def signal(self, int signum, ref=True, priority=None):
+        return signal(self, signum, ref, priority)
 
-    def idle(self, ref=True):
-        return idle(self, ref)
+    def idle(self, ref=True, priority=None):
+        return idle(self, ref, priority)
 
-    def prepare(self, ref=True):
-        return prepare(self, ref)
+    def prepare(self, ref=True, priority=None):
+        return prepare(self, ref, priority)
 
-    def fork(self, ref=True):
-        return fork(self, ref)
+    def fork(self, ref=True, priority=None):
+        return fork(self, ref, priority)
 
-    def async(self, ref=True):
-        return async(self, ref)
+    def async(self, ref=True, priority=None):
+        return async(self, ref, priority)
 
 #if EV_CHILD_ENABLE
 
 
 #endif
 
-    def stat(self, bytes path, float interval=0.0, ref=True):
-        return stat(self, path, interval, ref)
+    def stat(self, bytes path, float interval=0.0, ref=True, priority=None):
+        return stat(self, path, interval, ref, priority)
 
-    def callback(self):
-        return callback(self)
+    def callback(self, priority=None):
+        return callback(self, priority)
 
-    def run_callback(self, func, *args):
-        cdef callback result = callback(self)
+    def run_callback(self, func, *args, priority=None):
+        cdef callback result = callback(self, priority)
         result.start(func, *args)
         return result
 
 
 
 #define INIT(TYPE, ARGS_INITIALIZERS, ARGS)                                                \
-    def __init__(self, loop loop ARGS_INITIALIZERS, ref=True):                             \
+    def __init__(self, loop loop ARGS_INITIALIZERS, ref=True, priority=None):              \
         libev.ev_##TYPE##_init(&self._watcher, <void *>gevent_callback_##TYPE ARGS)        \
         self.loop = loop                                                                   \
         if ref:                                                                            \
             self._flags = 0                                                                \
         else:                                                                              \
-            self._flags = 4
+            self._flags = 4                                                                \
+        if priority is not None:                                                           \
+            libev.ev_set_priority(&self._watcher, priority)
+
 
 cdef public class watcher [object PyGeventWatcherObject, type PyGeventWatcher_Type]:
     """Abstract base class for all the watchers"""
 
 #ifdef _WIN32
 
-    def __init__(self, loop loop, long fd, int events, ref=True):
+    def __init__(self, loop loop, long fd, int events, ref=True, priority=None):
         if events & ~(libev.EV__IOFDSET | libev.EV_READ | libev.EV_WRITE):
             raise ValueError('illegal event mask: %r' % events)
         cdef int vfd = libev.vfd_open(fd)
             self._flags = 0
         else:
             self._flags = 4
+        if priority is not None:
+            libev.ev_set_priority(&self._watcher, priority)
 
 #else
 
-    def __init__(self, loop loop, int fd, int events, ref=True):
+    def __init__(self, loop loop, int fd, int events, ref=True, priority=None):
         if fd < 0:
             raise ValueError('fd must be non-negative: %r' % fd)
         if events & ~(libev.EV__IOFDSET | libev.EV_READ | libev.EV_WRITE):
             self._flags = 0
         else:
             self._flags = 4
+        if priority is not None:
+            libev.ev_set_priority(&self._watcher, priority)
 
 #endif
 
 
     PENDING
 
-    def __init__(self, loop loop, double after=0.0, double repeat=0.0, ref=True):
+    def __init__(self, loop loop, double after=0.0, double repeat=0.0, ref=True, priority=None):
         if repeat < 0.0:
             raise ValueError("repeat must be positive or zero: %r" % repeat)
         libev.ev_timer_init(&self._watcher, <void *>gevent_callback_timer, after, repeat)
             self._flags = 0
         else:
             self._flags = 4
+        if priority is not None:
+            libev.ev_set_priority(&self._watcher, priority)
 
     property at:
 
 
     WATCHER(signal)
 
-    def __init__(self, loop loop, int signalnum, ref=True):
+    def __init__(self, loop loop, int signalnum, ref=True, priority=None):
         if signalnum < 1 or signalnum >= signalmodule.NSIG:
             raise ValueError('illegal signal number: %r' % signalnum)
         # still possible to crash on one of libev's asserts:
             self._flags = 0
         else:
             self._flags = 4
+        if priority is not None:
+            libev.ev_set_priority(&self._watcher, priority)
 
 
 cdef public class idle(watcher) [object PyGeventIdleObject, type PyGeventIdle_Type]:
     WATCHER(stat)
     cdef readonly bytes path
 
-    def __init__(self, loop loop, bytes path, float interval=0.0, ref=True):
+    def __init__(self, loop loop, bytes path, float interval=0.0, ref=True, priority=None):
         self.path = path
         libev.ev_stat_init(&self._watcher, <void *>gevent_callback_stat, <char*>self.path, interval)
         self.loop = loop
             self._flags = 0
         else:
             self._flags = 4
+        if priority is not None:
+            libev.ev_set_priority(&self._watcher, priority)
 
     property attr: