Skip to content

Commit

Permalink
Merge pull request #12 from tortoise/master
Browse files Browse the repository at this point in the history
Performance tuning
  • Loading branch information
amyreese authored Sep 19, 2018
2 parents 729a088 + 48e3021 commit 96be14d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions aiosqlite/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,19 @@ async def _execute(self, fn, *args, **kwargs):
await self._lock.acquire()
pt = partial(fn, *args, **kwargs)
self._tx.put_nowait(pt)
while True:
try:
result = self._rx.get_nowait()
break

except Empty:
await asyncio.sleep(0.001)
continue
try:
# Many commands return nearly immediately (e.g. in a transaction)
result = self._rx.get(timeout=0.001)
except Empty:
# Now poll for longer queries
while True:
try:
result = self._rx.get_nowait()
break

except Empty:
await asyncio.sleep(0.001)
continue

self._lock.release()
if isinstance(result, Exception):
Expand Down

0 comments on commit 96be14d

Please sign in to comment.