Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make pool.release return future #60

Merged
merged 2 commits into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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