Merge pull request #1233 into develop
This commit is contained in:
commit
e3ee4ef951
|
@ -18,15 +18,19 @@ class UvNotFound(NotImplementedError):
|
||||||
|
|
||||||
|
|
||||||
pyuv = None
|
pyuv = None
|
||||||
|
pyuv_version_info = None
|
||||||
|
|
||||||
|
|
||||||
def import_pyuv():
|
def import_pyuv():
|
||||||
global pyuv
|
global pyuv
|
||||||
|
global pyuv_version_info
|
||||||
if not pyuv:
|
if not pyuv:
|
||||||
try:
|
try:
|
||||||
pyuv = __import__('pyuv')
|
pyuv = __import__('pyuv')
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise UvNotFound
|
raise UvNotFound
|
||||||
|
else:
|
||||||
|
pyuv_version_info = tuple((int(c) for c in pyuv.__version__.split('.')))
|
||||||
|
|
||||||
|
|
||||||
class UvThread(Thread):
|
class UvThread(Thread):
|
||||||
|
@ -34,14 +38,18 @@ class UvThread(Thread):
|
||||||
|
|
||||||
def __init__(self, loop):
|
def __init__(self, loop):
|
||||||
self.uv_loop = loop
|
self.uv_loop = loop
|
||||||
|
self.async_handle = pyuv.Async(loop, self._async_cb)
|
||||||
super(UvThread, self).__init__()
|
super(UvThread, self).__init__()
|
||||||
|
|
||||||
|
def _async_cb(self, handle):
|
||||||
|
self.uv_loop.stop()
|
||||||
|
self.async_handle.close()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
self.uv_loop.run()
|
||||||
self.uv_loop.run()
|
|
||||||
|
|
||||||
def join(self):
|
def join(self):
|
||||||
self.uv_loop.stop()
|
self.async_handle.send()
|
||||||
return super(UvThread, self).join()
|
return super(UvThread, self).join()
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,18 +80,30 @@ class UvWatcher(object):
|
||||||
self.lock = RLock()
|
self.lock = RLock()
|
||||||
self.loop = start_uv_thread()
|
self.loop = start_uv_thread()
|
||||||
self.fenc = get_preferred_file_name_encoding()
|
self.fenc = get_preferred_file_name_encoding()
|
||||||
|
if pyuv_version_info >= (1, 0):
|
||||||
|
self._start_watch = self._start_watch_1_x
|
||||||
|
else:
|
||||||
|
self._start_watch = self._start_watch_0_x
|
||||||
|
|
||||||
|
def _start_watch_1_x(self, path):
|
||||||
|
handle = pyuv.fs.FSEvent(self.loop)
|
||||||
|
handle.start(path, 0, partial(self._record_event, path))
|
||||||
|
self.watches[path] = handle
|
||||||
|
|
||||||
|
def _start_watch_0_x(self, path):
|
||||||
|
self.watches[path] = pyuv.fs.FSEvent(
|
||||||
|
self.loop,
|
||||||
|
path,
|
||||||
|
partial(self._record_event, path),
|
||||||
|
pyuv.fs.UV_CHANGE | pyuv.fs.UV_RENAME
|
||||||
|
)
|
||||||
|
|
||||||
def watch(self, path):
|
def watch(self, path):
|
||||||
path = normpath(path, self.fenc)
|
path = normpath(path, self.fenc)
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if path not in self.watches:
|
if path not in self.watches:
|
||||||
try:
|
try:
|
||||||
self.watches[path] = pyuv.fs.FSEvent(
|
self._start_watch(path)
|
||||||
self.loop,
|
|
||||||
path,
|
|
||||||
partial(self._record_event, path),
|
|
||||||
pyuv.fs.UV_CHANGE | pyuv.fs.UV_RENAME
|
|
||||||
)
|
|
||||||
except pyuv.error.FSEventError as e:
|
except pyuv.error.FSEventError as e:
|
||||||
code = e.args[0]
|
code = e.args[0]
|
||||||
if code == pyuv.errno.UV_ENOENT:
|
if code == pyuv.errno.UV_ENOENT:
|
||||||
|
|
Loading…
Reference in New Issue