pyuv: make stopping the loop thread-safe

This commit is contained in:
Saúl Ibarra Corretgé 2014-12-12 09:41:53 +01:00
parent f34ab66ea2
commit 36737867b1
1 changed files with 7 additions and 3 deletions

View File

@ -34,14 +34,18 @@ class UvThread(Thread):
def __init__(self, loop):
self.uv_loop = loop
self.async_handle = pyuv.Async(loop, self._async_cb)
super(UvThread, self).__init__()
def _async_cb(self, handle):
self.uv_loop.stop()
self.async_handle.close()
def run(self):
while True:
self.uv_loop.run()
self.uv_loop.run()
def join(self):
self.uv_loop.stop()
self.async_handle.send()
return super(UvThread, self).join()