为何Docker容器中运行Python代码触发asyncio超时,外部运行正常?
Docker环境下asyncio.wait_for无理由触发超时异常
我有一段Python脚本包含如下代码:
await asyncio.wait_for(subscriptionhandler(), 0.5)
这段代码作为自动化测试的一部分,在AWS服务器上稳定运行数周无问题。将测试环境迁移至Docker后,执行相同代码时,subscriptionhandler()可正常执行并退出,但上述代码仍会抛出asyncio超时异常。
我曾排查网络问题(与handler内操作相关),确认网络层面一切正常,该超时异常看似无合理触发原因。
相关配置文件
docker-compose.yml
debugservice: image: cypress/included:10.11.0 stdin_open: true # docker run -i tty: true # docker run -t privileged: true container_name: cypress # Name for the container working_dir: /opt/testing ports: - "9022:22" - "9200:9200" # network_mode: "host" volumes: - ${HOME}/.ssh/:/root/.ssh/ - /home/myuser/dev/auto-tests/cypress/e2e:/opt/testing/cypress/e2e - /home/myuser/dev/auto-tests/cypress/fixtures:/opt/testing/cypress/fixtures - /home/myuser/dev/auto-tests/cypress/pages:/opt/testing/cypress/pages - /home/myuser/dev/auto-tests/cypress.config.ts:/opt/testing/cypress.config.ts - /home/myuser/dev/auto-tests/tsconfig.json:/opt/testing/tsconfig.json - /home/myuser/dev/auto-tests/python/scripts:/opt/testing/python/scripts entrypoint: /bin/bash
Dockerfile
FROM cypress/browsers:node16.16.0-chrome105-ff104-edge ENV CI=1 \ QT_X11_NO_MITSHM=1 \ _X11_NO_MITSHM=1 \ _MITSHM=0 \ CYPRESS_CACHE_FOLDER=/root/.cache/Cypress \ NODE_PATH=/usr/local/lib/node_modules ARG CI_XBUILD RUN echo "whoami: $(whoami)" \ && npm config -g set user $(whoami) \ && id \ && apt-get install -y python3-pip \ && apt-get install -y python3-venv \ && ls -la /root \ && chmod 755 /root \ && npm i -g yarn@latest \ && node -p 'module.paths' \ && echo " node version: $(node -v) \n" \ "npm version: $(npm -v) \n" \ "yarn version: $(yarn -v) \n" \ "typescript version: $(tsc -v) \n" \ "debian version: $(cat /etc/debian_version) \n" \ "user: $(whoami) \n" \ "chrome: $(google-chrome --version || true) \n" \ "firefox: $(firefox --version || true) \n" WORKDIR /opt/testing/python RUN pwd COPY pycs . RUN --mount=type=secret,id=pip_conf,dst=/root/.pip/pip.conf pip install -r requirements.txt WORKDIR /opt/testing/cypress/support COPY cypress/support . WORKDIR /opt/testing COPY package.json . RUN npm install
内容的提问来源于stack exchange,提问作者Steve H
相关产品推荐
相关产品推荐

