gen_server call流程分析

本文深入解析了gen_servercall的工作流程,重点分析了your_modulehandler_call的四种返回情况及其对gen进程的影响,包括正常回复、超时处理及进程终止等关键细节。

gen_server call 流程分析

  • 关注your_module handler_call的返回值:
    • {reply, Reply, NState} 表示正常,给gen进程发通知,并继续循环接收数据,无超时时间
    • {reply, Reply, NState, Timeout} 表示正常,给gen进程发通知,并继续循环接收数据,超时时间为Timeout
    • {noreply, Reply, NState} 表示正常,不会给gen进程发通知,gen进程只能等待超时,并继续循环接收数据,无超时时间
    • {noreply, Reply, NState, Timeout}表示正常,不会给gen进程发通知,gen进程只能等待超时,并继续循环接收数据,超时时间为Timeout
    • {stop, Reason, Reply, NState}表示异常,终止进程
      gen_server模块call流程分析
Exception Group Traceback (most recent call last): | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\_utils.py", line 76, in collapse_excgroups | yield | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 186, in __call__ | async with anyio.create_task_group() as task_group: | │ │ └ <anyio._backends._asyncio.TaskGroup object at 0x00000168B3F1F4F0> | │ └ <function create_task_group at 0x00000168A54857E0> | └ <module 'anyio' from 'D:\\dev\\EquipmentRegistryDataPlatform\\venv\\lib\\site-packages\\anyio\\__init__.py'> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 815, in __aexit__ | raise BaseExceptionGroup( | └ <class 'exceptiongroup.BaseExceptionGroup'> | | exceptiongroup.ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) +-+---------------- 1 ---------------- | Traceback (most recent call last): | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 403, in run_asgi | result = await app( # type: ignore[func-returns-value] | └ <uvicorn.middleware.proxy_headers.ProxyHeadersMiddleware object at 0x00000168A4F34760> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 60, in __call__ | return await self.app(scope, receive, send) | │ │ │ │ └ <bound method RequestResponseCycle.send of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x00000168B3F1E860>> | │ │ │ └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x00000168B3F1E... | │ │ └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('172.23.49.43', 9999), ... | │ └ <fastapi.applications.FastAPI object at 0x00000168B3AF1D50> | └ <uvicorn.middleware.proxy_headers.ProxyHeadersMiddleware object at 0x00000168A4F34760> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\fastapi\applications.py", line 1054, in __call__ | await super().__call__(scope, receive, send) | │ │ └ <bound method RequestResponseCycle.send of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x00000168B3F1E860>> | │ └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x00000168B3F1E... | └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('172.23.49.43', 9999), ... | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\applications.py", line 113, in __call__ | await self.middleware_stack(scope, receive, send) | │ │ │ │ └ <bound method RequestResponseCycle.send of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x00000168B3F1E860>> | │ │ │ └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x00000168B3F1E... | │ │ └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('172.23.49.43', 9999), ... | │ └ <starlette.middleware.errors.ServerErrorMiddleware object at 0x00000168B3D038E0> | └ <fastapi.applications.FastAPI object at 0x00000168B3AF1D50> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\errors.py", line 187, in __call__ | raise exc | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\errors.py", line 165, in __call__ | await self.app(scope, receive, _send) | │ │ │ │ └ <function ServerErrorMiddleware.__call__.<locals>._send at 0x00000168A65497E0> | │ │ │ └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x00000168B3F1E... | │ │ └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('172.23.49.43', 9999), ... | │ └ <starlette.middleware.cors.CORSMiddleware object at 0x00000168B3D038B0> | └ <starlette.middleware.errors.ServerErrorMiddleware object at 0x00000168B3D038E0> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\cors.py", line 93, in __call__ | await self.simple_response(scope, receive, send, request_headers=headers) | │ │ │ │ │ └ Headers({'host': '172.23.49.43:9999', 'connection': 'keep-alive', 'content-length': '117', 'pragma': 'no-cache', 'cache-contr... | │ │ │ │ └ <function ServerErrorMiddleware.__call__.<locals>._send at 0x00000168A65497E0> | │ │ │ └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x00000168B3F1E... | │ │ └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('172.23.49.43', 9999), ... | │ └ <function CORSMiddleware.simple_response at 0x00000168B3AF7490> | └ <starlette.middleware.cors.CORSMiddleware object at 0x00000168B3D038B0> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\cors.py", line 144, in simple_response | await self.app(scope, receive, send) | │ │ │ │ └ functools.partial(<bound method CORSMiddleware.send of <starlette.middleware.cors.CORSMiddleware object at 0x00000168B3D038B0... | │ │ │ └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x00000168B3F1E... | │ │ └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('172.23.49.43', 9999), ... | │ └ <app.core.middlewares.BackGroundTaskMiddleware object at 0x00000168B3D03850> | └ <starlette.middleware.cors.CORSMiddleware object at 0x00000168B3D038B0> | | File "D:\dev\EquipmentRegistryDataPlatform\app\core\middlewares.py", line 28, in __call__ | await self.handle_http(scope, receive, send) | │ │ │ │ └ functools.partial(<bound method CORSMiddleware.send of <starlette.middleware.cors.CORSMiddleware object at 0x00000168B3D038B0... | │ │ │ └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x00000168B3F1E... | │ │ └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('172.23.49.43', 9999), ... | │ └ <function SimpleBaseMiddleware.handle_http at 0x00000168B3B141F0> | └ <app.core.middlewares.BackGroundTaskMiddleware object at 0x00000168B3D03850> | | File "D:\dev\EquipmentRegistryDataPlatform\app\core\middlewares.py", line 38, in handle_http | await response(scope, receive, send_wrapper) | │ │ │ └ <function SimpleBaseMiddleware.handle_http.<locals>.send_wrapper at 0x00000168A6549A20> | │ │ └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x00000168B3F1E... | │ └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('172.23.49.43', 9999), ... | └ <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 185, in __call__ | with collapse_excgroups(): | └ <function collapse_excgroups at 0x00000168A56A4940> | | File "C:\Program Files\Python310\lib\contextlib.py", line 153, in __exit__ | self.gen.throw(typ, value, traceback) | │ │ │ │ │ └ <traceback object at 0x00000168B523ABC0> | │ │ │ │ └ ExceptionGroup('unhandled errors in a TaskGroup', [TypeError("Unable to apply constraint 'max_length' to supplied value 2025-... | │ │ │ └ <class 'exceptiongroup.ExceptionGroup'> | │ │ └ <method 'throw' of 'generator' objects> | │ └ <generator object collapse_excgroups at 0x00000168B507E1F0> | └ <contextlib._GeneratorContextManager object at 0x00000168B3F1E830> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\_utils.py", line 82, in collapse_excgroups | raise exc | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 187, in __call__ | response = await self.dispatch_func(request, call_next) | │ │ │ └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x00000168A6549990> | │ │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | │ └ <bound method APILoggerMiddleware.dispatch of <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0>> | └ <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0> | | File "D:\dev\EquipmentRegistryDataPlatform\app\core\middlewares.py", line 103, in dispatch | response = await call_next(request) | │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x00000168A6549990> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 163, in call_next | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\_utils.py", line 82, in collapse_excgroups | raise exc | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 187, in __call__ | response = await self.dispatch_func(request, call_next) | │ │ │ └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x00000168A6549990> | │ │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | │ └ <bound method APILoggerMiddleware.dispatch of <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0>> | └ <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0> | | File "D:\dev\EquipmentRegistryDataPlatform\app\core\middlewares.py", line 103, in dispatch | response = await call_next(request) | │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x00000168A6549990> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 163, in call_next | raise exc | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 187, in __call__ | response = await self.dispatch_func(request, call_next) | │ │ │ └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x00000168A6549990> | │ │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | │ └ <bound method APILoggerMiddleware.dispatch of <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0>> | └ <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0> | | File "D:\dev\EquipmentRegistryDataPlatform\app\core\middlewares.py", line 103, in dispatch | response = await call_next(request) | │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x00000168A6549990> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 163, in call_next | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 187, in __call__ | response = await self.dispatch_func(request, call_next) | │ │ │ └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x00000168A6549990> | │ │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | │ └ <bound method APILoggerMiddleware.dispatch of <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0>> | └ <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0> | | File "D:\dev\EquipmentRegistryDataPlatform\app\core\middlewares.py", line 103, in dispatch | response = await call_next(request) | │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x00000168A6549990> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 163, in call_next | │ │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | │ └ <bound method APILoggerMiddleware.dispatch of <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0>> | └ <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0> | | File "D:\dev\EquipmentRegistryDataPlatform\app\core\middlewares.py", line 103, in dispatch | response = await call_next(request) | │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x00000168A6549990> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 163, in call_next | File "D:\dev\EquipmentRegistryDataPlatform\app\core\middlewares.py", line 103, in dispatch | response = await call_next(request) | │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x00000168A6549990> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 163, in call_next | │ └ <starlette.middleware.base._CachedRequest object at 0x00000168B3F1E950> | └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x00000168A6549990> | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 163, in call_next | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 163, in call_next | raise app_exc | └ TypeError("Unable to apply constraint 'max_length' to supplied value 2025-08-24 16:00:00+00:00") | | raise app_exc | └ TypeError("Unable to apply constraint 'max_length' to supplied value 2025-08-24 16:00:00+00:00") | | └ TypeError("Unable to apply constraint 'max_length' to supplied value 2025-08-24 16:00:00+00:00") | | File "D:\dev\EquipmentRegistryDataPlatform\venv\lib\site-packages\starlette\middleware\base.py", line 149, in coro | await self.app(scope, receive_or_disconnect, send_no_error) | │ │ │ │ └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.send_no_error at 0x00000168A654AA70> | │ │ │ └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnect at 0x00000168A6549900> | │ │ └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('172.23.49.43', 9999), ... | │ └ <app.core.middlewares.APILoggerAddResponseMiddleware object at 0x00000168B3D03730> | └ <app.core.middlewares.APILoggerMiddleware object at 0x00000168B3D037F0> | | File "D:\dev\EquipmentRegistryDataPlatform\app\core\middlewares.py", line 28, in __call__ | await self.handle_http(scope, receive, send) | │ │ │ │ └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.send_no_error at 0x00000168A654AA70> | │ │ │ └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnect at 0x00000168A654WARNING: StatReload detected changes in 'app\api\v1\zentao\zt_materiallib.py'. Reloading...
最新发布
08-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值