async python error while running api in docker asyncpg.exceptions._base.InterfaceError

1.8k views Asked by At

I am making an api in quart which is based on aiohttp in python and its an asynchronous library and when i run the api locally everything runs fine but if i run it on docker it gives me errors on endpoints

api_1  |   File "asyncpg/protocol/protocol.pyx", line 301, in query
api_1  |   File "asyncpg/protocol/protocol.pyx", line 664, in asyncpg.protocol.protocol.BaseProtocol._check_state
api_1  | asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress

This is on an endpoint which works fine locally

Dockerfile

FROM python:3.8-slim

# left to be done after project structure
WORKDIR /app

ADD . /app

RUN pip install pipenv
RUN pipenv install --system --deploy
CMD python launch.py initdb
CMD sh /app/runfile.sh

runfile.sh

hypercorn launch:app -b 0.0.0.0:5000

Dockerfile after applying change that was suggested

FROM python:3.8-alpine

# left to be done after project structure
WORKDIR /app

ADD . /app

RUN apk add gcc python3-dev musl-dev

RUN pip install pipenv
RUN pipenv install --system --deploy
CMD python launch.py initdb
CMD sh /app/runfile.sh
1

There are 1 answers

1
Akihito KIRISAKI On

I have found a solution. The problem is lacking of connections in pool. so await connection with using acquire() like as mentioned above.