diff --git a/gevent/core.ppyx b/gevent/core.ppyx index 328700a95e0482613ff0aeade35dc19d19535731..8e019c0d8006a99359386169e117437c2c6ebfd2 100644 --- a/gevent/core.ppyx +++ b/gevent/core.ppyx @@ -6,6 +6,7 @@ import sys import os import traceback import signal as signalmodule +SIGCHLD = getattr(signalmodule, 'SIGCHLD', None) __all__ = ['get_version', @@ -228,6 +229,7 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]: cdef libev.ev_loop* _ptr cdef public object error_handler cdef libev.ev_prepare _signal_checker + cdef public int nochild #ifdef _WIN32 cdef libev.ev_timer _periodic_signal_checker #endif @@ -235,6 +237,7 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]: def __init__(self, object flags=None, object default=True, size_t ptr=0): cdef unsigned int c_flags cdef object old_handler = None + self.nochild = 0 libev.ev_prepare_init(&self._signal_checker, <void*>gevent_signal_check) #ifdef _WIN32 libev.ev_timer_init(&self._periodic_signal_checker, <void*>gevent_periodic_signal_check, 0.3, 0.3) @@ -249,12 +252,15 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]: default = False if default: if c_flags & c_NOCHILD: - old_handler = signalmodule.getsignal(signalmodule.SIGCHLD) + self.nochild = 1 + if SIGCHLD is not None: + old_handler = signalmodule.getsignal(SIGCHLD) self._ptr = libev.ev_default_loop(c_flags) if not self._ptr: raise SystemError("ev_default_loop(%s) failed" % (c_flags, )) - if c_flags & c_NOCHILD: - signalmodule.signal(signalmodule.SIGCHLD, old_handler) + if self.nochild: + if SIGCHLD is not None: + signalmodule.signal(SIGCHLD, old_handler) libev.ev_prepare_start(self._ptr, &self._signal_checker) libev.ev_unref(self._ptr) #ifdef _WIN32 @@ -419,10 +425,14 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]: def async(self, ref=True): return async(self, ref) - def child(self, int pid, bint trace=0): - if self._ptr.origflags & c_NOCHILD: +#if EV_CHILD_ENABLE + + def child(self, int pid, bint trace=0, ref=True): + if self.nochild: raise TypeError('child watchers are not available because "nochild" is in effect') - return child(self, pid, trace) + return child(self, pid, trace, ref) + +#endif def callback(self): return callback(self) @@ -828,6 +838,7 @@ cdef public class async(watcher) [object PyGeventAsyncObject, type PyGeventAsync def send(self): libev.ev_async_send(self.loop._ptr, &self._watcher) +#if EV_CHILD_ENABLE cdef public class child(watcher) [object PyGeventChildObject, type PyGeventChild_Type]: @@ -864,6 +875,8 @@ cdef public class child(watcher) [object PyGeventChildObject, type PyGeventChild def __set__(self, int value): self._watcher.rstatus = value +#endif + cdef public class callback(watcher) [object PyGeventCallbackObject, type PyGeventCallback_Type]: """Pseudo-watcher used to execute a callback in the loop as soon as possible."""