Commit b877b041 authored by Denis Bilenko's avatar Denis Bilenko

core.ppyx: fix compilation on windows where 'child' watchers are not...

core.ppyx: fix compilation on windows where 'child' watchers are not available; add 'ref' argument to child() function of loop
parent 4a8aae6d
...@@ -6,6 +6,7 @@ import sys ...@@ -6,6 +6,7 @@ import sys
import os import os
import traceback import traceback
import signal as signalmodule import signal as signalmodule
SIGCHLD = getattr(signalmodule, 'SIGCHLD', None)
__all__ = ['get_version', __all__ = ['get_version',
...@@ -228,6 +229,7 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]: ...@@ -228,6 +229,7 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
cdef libev.ev_loop* _ptr cdef libev.ev_loop* _ptr
cdef public object error_handler cdef public object error_handler
cdef libev.ev_prepare _signal_checker cdef libev.ev_prepare _signal_checker
cdef public int nochild
#ifdef _WIN32 #ifdef _WIN32
cdef libev.ev_timer _periodic_signal_checker cdef libev.ev_timer _periodic_signal_checker
#endif #endif
...@@ -235,6 +237,7 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]: ...@@ -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): def __init__(self, object flags=None, object default=True, size_t ptr=0):
cdef unsigned int c_flags cdef unsigned int c_flags
cdef object old_handler = None cdef object old_handler = None
self.nochild = 0
libev.ev_prepare_init(&self._signal_checker, <void*>gevent_signal_check) libev.ev_prepare_init(&self._signal_checker, <void*>gevent_signal_check)
#ifdef _WIN32 #ifdef _WIN32
libev.ev_timer_init(&self._periodic_signal_checker, <void*>gevent_periodic_signal_check, 0.3, 0.3) 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]: ...@@ -249,12 +252,15 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
default = False default = False
if default: if default:
if c_flags & c_NOCHILD: 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) self._ptr = libev.ev_default_loop(c_flags)
if not self._ptr: if not self._ptr:
raise SystemError("ev_default_loop(%s) failed" % (c_flags, )) raise SystemError("ev_default_loop(%s) failed" % (c_flags, ))
if c_flags & c_NOCHILD: if self.nochild:
signalmodule.signal(signalmodule.SIGCHLD, old_handler) if SIGCHLD is not None:
signalmodule.signal(SIGCHLD, old_handler)
libev.ev_prepare_start(self._ptr, &self._signal_checker) libev.ev_prepare_start(self._ptr, &self._signal_checker)
libev.ev_unref(self._ptr) libev.ev_unref(self._ptr)
#ifdef _WIN32 #ifdef _WIN32
...@@ -419,10 +425,14 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]: ...@@ -419,10 +425,14 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
def async(self, ref=True): def async(self, ref=True):
return async(self, ref) return async(self, ref)
def child(self, int pid, bint trace=0): #if EV_CHILD_ENABLE
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') 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): def callback(self):
return callback(self) return callback(self)
...@@ -828,6 +838,7 @@ cdef public class async(watcher) [object PyGeventAsyncObject, type PyGeventAsync ...@@ -828,6 +838,7 @@ cdef public class async(watcher) [object PyGeventAsyncObject, type PyGeventAsync
def send(self): def send(self):
libev.ev_async_send(self.loop._ptr, &self._watcher) libev.ev_async_send(self.loop._ptr, &self._watcher)
#if EV_CHILD_ENABLE
cdef public class child(watcher) [object PyGeventChildObject, type PyGeventChild_Type]: cdef public class child(watcher) [object PyGeventChildObject, type PyGeventChild_Type]:
...@@ -864,6 +875,8 @@ cdef public class child(watcher) [object PyGeventChildObject, type PyGeventChild ...@@ -864,6 +875,8 @@ cdef public class child(watcher) [object PyGeventChildObject, type PyGeventChild
def __set__(self, int value): def __set__(self, int value):
self._watcher.rstatus = value self._watcher.rstatus = value
#endif
cdef public class callback(watcher) [object PyGeventCallbackObject, type PyGeventCallback_Type]: cdef public class callback(watcher) [object PyGeventCallbackObject, type PyGeventCallback_Type]:
"""Pseudo-watcher used to execute a callback in the loop as soon as possible.""" """Pseudo-watcher used to execute a callback in the loop as soon as possible."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment