Commit c8e473aa authored by Jason Madden's avatar Jason Madden

Improvements to path watching: set the path earlier, make the test more comprehensive.

parent 546c5218
......@@ -1067,19 +1067,29 @@ class stat(watcher):
_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
if not isinstance(path, bytes):
# XXX: Filesystem encoding? Python itself has issues here, were they fixed?
path = path.encode('utf-8')
watcher.__init__(self, _loop, ref=ref, priority=priority,
# cffi doesn't automatically marshal byte strings to
# char* in the function call; instead it passes an
# empty string or garbage pointer. If the watcher's
# path is incorrect, watching silently fails
# (the underlying call to lstat() keeps erroring out)
args=(ffi.new('char[]', path),
interval))
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 path(self):
return ffi.string(self._watcher.path)
@property
def attr(self):
if not self._watcher.attr.st_nlink:
......
......@@ -23,7 +23,14 @@ try:
f.close()
greenlet = gevent.spawn_later(DELAY, write)
watcher = hub.loop.stat(filename)
# If we don't specify an interval, we default to zero.
# libev interprets that as meaning to use its default interval,
# which is about 5 seconds. If we go below it's minimum check
# threshold, it bumps it up to the minimum.
watcher = hub.loop.stat(filename, interval=-1)
if hasattr(watcher, 'path'):
assert watcher.path == filename
assert watcher.interval == -1
start = time.time()
......@@ -37,6 +44,8 @@ try:
assert reaction >= 0.0, 'Watcher %s reacted too early (write): %.3fs' % (watcher, reaction)
assert watcher.attr is not None, watcher.attr
assert watcher.prev is not None, watcher.prev
# The watcher interval changed after it started; -1 is illegal
assert watcher.interval != -1
greenlet.join()
gevent.spawn_later(DELAY, os.unlink, filename)
......
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