1. Jeff Knupp
  2. gevent-py3k


Denis Bilenko  committed 7407c1f

core.ppyx: fix compilation on windows where 'child' watchers are not available; add 'ref' argument to child() function of loop

  • Participants
  • Parent commits 20af044
  • Branches default

Comments (0)

Files changed (1)

File gevent/core.ppyx

View file
 import os
 import traceback
 import signal as signalmodule
+SIGCHLD = getattr(signalmodule, 'SIGCHLD', None)
 __all__ = ['get_version',
     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
     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)
                 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)
 #ifdef _WIN32
     def async(self, ref=True):
         return async(self, ref)
-    def child(self, int pid, bint trace=0):
-        if self._ptr.origflags & c_NOCHILD:
+    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)
     def callback(self):
         return callback(self)
     def send(self):
         libev.ev_async_send(self.loop._ptr, &self._watcher)
 cdef public class child(watcher) [object PyGeventChildObject, type PyGeventChild_Type]:
         def __set__(self, int value):
             self._watcher.rstatus = value
 cdef public class callback(watcher) [object PyGeventCallbackObject, type PyGeventCallback_Type]:
     """Pseudo-watcher used to execute a callback in the loop as soon as possible."""