Skip to content

Commit

Permalink
Merge pull request #60 from aio-libs/improve-pool-release
Browse files Browse the repository at this point in the history
make pool.release return future
  • Loading branch information
jettify committed Jan 20, 2016
2 parents 52149b6 + c4587e1 commit 91deaba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion aiomysql/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ def release(self, conn):
conn.close()
else:
self._free.append(conn)
asyncio.Task(self._wakeup(), loop=self._loop)
fut = asyncio.Task(self._wakeup(), loop=self._loop)
else:
fut = asyncio.Future(loop=self._loop)
fut.set_result(None)
return fut

def get(self):
warnings.warn("pool.get deprecated use pool.acquire instead",
Expand Down
4 changes: 1 addition & 3 deletions aiomysql/sa/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ def release(self, conn):
raise InvalidRequestError("Cannot release a connection with "
"not finished transaction")
raw = conn.connection
if raw is None:
return
self._pool.release(raw)
return self._pool.release(raw)

def __enter__(self):
raise RuntimeError(
Expand Down
10 changes: 6 additions & 4 deletions aiomysql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ def __aenter__(self):

@asyncio.coroutine
def __aexit__(self, exc_type, exc, tb):
self._pool.release(self._conn)
self._pool = None
self._conn = None
try:
yield from self._pool.release(self._conn)
finally:
self._pool = None
self._conn = None


class _PoolConnectionContextManager:
Expand Down Expand Up @@ -177,7 +179,7 @@ def __aenter__(self):
@asyncio.coroutine
def __aexit__(self, exc_type, exc_val, exc_tb):
try:
self._pool.release(self._conn)
yield from self._pool.release(self._conn)
finally:
self._pool = None
self._conn = None
Expand Down

0 comments on commit 91deaba

Please sign in to comment.