Open msean opened 7 years ago
Probably that's some kind of edge case with uvloop
and aiopg
. Does this error happen without uvloop
?
I have this bug without uvloop.
Yes. I have the same issue. I wanna testing my model with aiohttp and unit test. I would try to solve it for an other driver, local threads parameters or override event loop. But looks like its not helpful, manage connections has no effect too. It's just testing, what if that issue will happen in a production.
You should explicity call objects.close()
before close event loop
I get this while performing unit tests.
I have a series of simple tests to grab an entity with a simple manager context query. If I try to execute more than one during a test, I get this error.
_common/common/db/getters.py:82: in get_generic
return await entity_getter(node_tag=node_tag, client_code=client_code)
_common/common/db/getters.py:17: in get_store
Client.code ** client_code
/home/adam/.virtualenvs/mxtest/lib/python3.6/site-packages/peewee_async.py:169: in get
result = yield from self.execute(query)
/home/adam/.virtualenvs/mxtest/lib/python3.6/site-packages/peewee_async.py:269: in execute
return (yield from execute(query))
/home/adam/.virtualenvs/mxtest/lib/python3.6/site-packages/peewee_async.py:433: in execute
return (yield from coroutine(query))
/home/adam/.virtualenvs/mxtest/lib/python3.6/site-packages/peewee_async.py:574: in select
cursor = yield from _execute_query_async(query)
/home/adam/.virtualenvs/mxtest/lib/python3.6/site-packages/peewee_async.py:1555: in _execute_query_async
return (yield from _run_sql(query.database, *query.sql()))
/home/adam/.virtualenvs/mxtest/lib/python3.6/site-packages/peewee_async.py:1542: in _run_sql
return cursor
/home/adam/.virtualenvs/mxtest/lib/python3.6/site-packages/peewee.py:3656: in __exit__
reraise(new_type, new_type(*exc_args), traceback)
/home/adam/.virtualenvs/mxtest/lib/python3.6/site-packages/peewee.py:135: in reraise
raise value.with_traceback(tb)
/home/adam/.virtualenvs/mxtest/lib/python3.6/site-packages/peewee_async.py:1539: in _run_sql
yield from cursor.release
/usr/lib/python3.6/asyncio/coroutines.py:210: in coro
res = func(*args, **kw)
/home/adam/.virtualenvs/mxtest/lib/python3.6/site-packages/peewee_async.py:1107: in release_cursor
cursor.close()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <aiopg.cursor.Cursor object at 0x7fc48e910fd0>
def close(self):
"""Close the cursor now."""
> self._impl.close()
E peewee.ProgrammingError: close cannot be used while an asynchronous query is underway
/home/adam/.virtualenvs/mxtest/lib/python3.6/site-packages/aiopg/cursor.py:51: ProgrammingError
I was getting this same issue.
peewee.ProgrammingError: close cannot be used while an asynchronous query is underway
After tracing through the issue, I determined it was due to my setup with pytest-asyncio since that library does the following in the default event_loop fixture:
Creates and injects a new instance of the default asyncio event loop. By default, the loop will be closed at the end of the test (i.e. the default fixture scope is function).
To fix the issue, I created a conftest.py file at the root of my tests that has the following replacement fixture.
import pytest
import asyncio
@pytest.fixture(scope='session')
def event_loop():
return asyncio.new_event_loop()
Maybe this will help someone else who lands here from google.
Renctly I tried to redeploy my project used with sanic frame ,some errors happened when I do a test under high-concurrency. info in the log:
and the traceback is below:
what caused this problem?