def gevent_callback(watcher, revents):
    gevent_check_signals(watcher.loop)
    if watcher.args is not None and len(watcher.args) > 0 and watcher.args[0] == GEVENT_CORE_EVENTS:
        watcher.args[0] = revents

    watcher._callback(*watcher.args)

    if not libev.ev_is_active(pointer(watcher._watcher_struct)):
        watcher.stop()
 def set_ref(self, value):
     if value:
         if not self._flags & 4:
             return  # ref is already True
         if self._flags & 2:  # ev_unref was called, undo
             libev.ev_ref(self.loop._ptr)
         self._flags &= ~6  # do not want unref, no outstanding unref
     else:
         if self._flags & 4:
             return  # ref is already False
         self._flags |= 4
         if not self._flags & 2 and libev.ev_is_active(pointer(self._watcher_struct)):
             libev.ev_unref(self.loop._ptr)
             self._flags |= 2
 def set_events(self, events):
     if libev.ev_is_active(pointer(self._watcher_struct)):
         raise AttributeError("'io' watcher attribute 'events' is read-only while watcher is active")
     self._watcher_init(self._watcher_struct, self._watcher_callback, self._watcher_struct.fd, events)
 def active(self):
     return True if libev.ev_is_active(pointer(self._watcher_struct)) else False
 def set_priority(self, priority):
     if libev.ev_is_active(pointer(self._watcher_struct)):
         raise AttributeError("Cannot set priority of an active watcher")
     libev.ev_set_priority(pointer(self._watcher_struct), priority)
 def _stop_signal_checker(self):
     if libev.ev_is_active(pointer(self._signal_checker)):
         libev.ev_ref(self._ptr)
         libev.ev_prepare_stop(self._ptr, pointer(self._signal_checker))