Use with section for locking threadsafe region (instead of raw calls to acquire/release)

This commit is contained in:
nemunaire 2015-09-05 10:14:10 +02:00
commit 7970fca93a
2 changed files with 48 additions and 52 deletions

View file

@ -71,17 +71,15 @@ class AbstractServer(io.IOBase):
"""Generic close function that register the server un _{r,w,x}list in
case of successful _close"""
self.logger.info("Closing connection to %s", self.id)
_lock.acquire()
if not hasattr(self, "_close") or self._close():
if self in _rlist:
_rlist.remove(self)
if self in _wlist:
_wlist.remove(self)
if self in _xlist:
_xlist.remove(self)
_lock.release()
return True
_lock.release()
with _lock:
if not hasattr(self, "_close") or self._close():
if self in _rlist:
_rlist.remove(self)
if self in _wlist:
_wlist.remove(self)
if self in _xlist:
_xlist.remove(self)
return True
return False