Commit 546c5218 authored by Jason Madden's avatar Jason Madden

Implement stat watchers on PyPy.

parent 9661f035
...@@ -114,6 +114,7 @@ struct stat { ...@@ -114,6 +114,7 @@ struct stat {
struct ev_stat { struct ev_stat {
struct stat attr; struct stat attr;
const char* path;
struct stat prev; struct stat prev;
double interval; double interval;
...; ...;
...@@ -648,6 +649,9 @@ class loop(object): ...@@ -648,6 +649,9 @@ class loop(object):
def install_sigchld(self): def install_sigchld(self):
libev.gevent_install_sigchld_handler() libev.gevent_install_sigchld_handler()
def stat(self, path, interval=0.0, ref=True, priority=None):
return stat(self, path, interval, ref, priority)
def callback(self, priority=None): def callback(self, priority=None):
return callback(self, priority) return callback(self, priority)
...@@ -1054,6 +1058,43 @@ class child(watcher): ...@@ -1054,6 +1058,43 @@ class child(watcher):
def rstatus(self, value): def rstatus(self, value):
self._watcher.rstatus = value self._watcher.rstatus = value
class stat(watcher):
_watcher_start = libev.ev_stat_start
_watcher_stop = libev.ev_stat_stop
_watcher_init = libev.ev_stat_init
_watcher_type = 'ev_stat'
_watcher_ffi_type = "struct %s *" % _watcher_type
_watcher_ffi_cb = "void(*)(struct ev_loop *, struct %s *, int)" % _watcher_type
def __init__(self, _loop, path, interval=0.0, ref=True, priority=None):
self.path = path
watcher.__init__(self, _loop, ref=ref, priority=priority, args=(path, interval))
# XXX: self._watcher.path is not getting properly set at the C level
# (Possibly because ev_stat_init is actually a macro? I don't know)
# Something overwrites it or fails to set it. We reset it in start() method
def start(self, callback, *args):
self._watcher.path = ffi.new("char[]", self.path)
watcher.start(self, callback, *args)
def stop(self):
watcher.stop(self)
@property
def attr(self):
if not self._watcher.attr.st_nlink:
return
return self._watcher.attr
@property
def prev(self):
if not self._watcher.prev.st_nlink:
return
return self._watcher.prev
@property
def interval(self):
return self._watcher.interval
def _syserr_cb(msg): def _syserr_cb(msg):
try: try:
......
...@@ -58,9 +58,6 @@ if PYPY: ...@@ -58,9 +58,6 @@ if PYPY:
FAILING_TESTS += [ FAILING_TESTS += [
# Not implemented: # Not implemented:
# stat watchers are not implemented on pypy
'test__core_stat.py',
# ares not supported on PyPy yet # ares not supported on PyPy yet
'test__ares_host_result.py', 'test__ares_host_result.py',
......
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