RuntimeError:无法对tcptTransport执行操作处理程序已关闭

2024-05-31 20:51:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图在本地机器上用autocannon工具对我的新的、全新的项目设置进行HTTP基准测试,我的项目设置是建立在FastAPI+uvicorn之上的。你知道吗

但是在某个时刻或者随机的(我不知道发生了什么)我有一个ASGI异常。你知道吗

[2019-11-14 14:16:40 +0100] [98098] [ERROR] Exception in ASGI application
Traceback (most recent call last):
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 385, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/fastapi/applications.py", line 139, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/applications.py", line 134, in __call__
    await self.error_middleware(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/middleware/errors.py", line 178, in __call__
    raise exc from None
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/middleware/errors.py", line 156, in __call__
    await self.app(scope, receive, _send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/exceptions.py", line 73, in __call__
    raise exc from None
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/exceptions.py", line 62, in __call__
    await self.app(scope, receive, sender)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/routing.py", line 590, in __call__
    await route(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/routing.py", line 208, in __call__
    await self.app(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/routing.py", line 44, in app
    await response(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/responses.py", line 125, in __call__
    "headers": self.raw_headers,
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/exceptions.py", line 59, in sender
    await send(message)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/middleware/errors.py", line 153, in _send
    await send(message)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 482, in send
    self.transport.write(b"".join(content))
  File "uvloop/handles/stream.pyx", line 673, in uvloop.loop.UVStream.write
  File "uvloop/handles/handle.pyx", line 159, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x7fb255569780>; the handler is closed

要启动我的应用程序,我需要:

gunicorn url_shortener:app -w 1 -k uvicorn.workers.UvicornWorker

I tried to raise the number of the workers. I still get these exceptions.

要进行基准测试,我需要:

autocannon -c 100 -d 40 -p 10 localhost:8000/shorten -H "Content-Type: application/json" -m POST -b '{"url": "http://yigitgenc.com"}'

注意:我的数据库(PostgreSQL)在Docker容器上工作。我也做异步数据库交互(当然)。也许添加这些信息会有帮助。你知道吗


Tags: inpysendurllibpackageslinesite