asgi-server-timing-middleware
asgi-server-timing-middleware copied to clipboard
Cython functions aren't supported because of the way `inspect.isfunction` works
inspect.isfunction
returns False
for Cython functions (see this discussion).
As a result, tracking pydantic.fields.ModelField.validate
for pydantic==1.7.3
is impossible.
Is this exclusive to Cython functions or would any C function cause that problem? Your mailing list thread links to pep-0575, which in turn links to pep-0579, and both seem to recommend making changes to inspect.isfunction
that don't seem to have gone through.
There's always the possibility of just going the duck-typing route and searching for a __code__
attribute on the functions, possibly alongside an extra check to ensure the functions being passed aren't bound methods (which I believe didn't work with yappi, but I would have to double-check), which seems to be what's recommended in the case of Cython, but some testing will be needed in that regard.
I don't have any deep insight into this: I've found your repo while exploring different options for FastAPI profiling, tried to run the example in smoke_test.py
, and hit that exception. So I only have an example of a Cython function.
I just tried replacing inspect.isfunction(profiled)
with inspect.isroutine(profiled)
(inspired by this), and it worked in the sense that Yappi didn't complain and returned YFuncStats
containing Cython functions (and bound methods, too). The numbers look OK.
callable(profiled)
might be another option. I'll check and report tomorrow.
FWIW - this stopped pydantic.fields.ModelField.validate
(included in the readme) from working correctly because inspect.isfunction
returns False. validate
is a cython function.
Changing to callable(profiled)
worked