Skip to content

Commit

Permalink
Improve perf of stack inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet committed Dec 8, 2024
1 parent 9994b74 commit a097cee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions blockbuster/blockbuster.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ def wrapper(*args: Any, **kwargs: Any) -> _T:
asyncio.get_running_loop()
except RuntimeError:
return func(*args, **kwargs)
for filename, functions in can_block_functions:
for frame_info in inspect.stack():
if (
frame_info.filename.endswith(filename)
and frame_info.function in functions
):
return func(*args, **kwargs)
if can_block_functions:
frame = inspect.currentframe()
while frame:
frame_info = inspect.getframeinfo(frame)
for filename, functions in can_block_functions:
if (
frame_info.filename.endswith(filename)
and frame_info.function in functions
):
return func(*args, **kwargs)
frame = frame.f_back
if can_block_predicate(*args, **kwargs):
return func(*args, **kwargs)
raise _blocking_error(func)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "blockbuster"
version = "1.3.1"
version = "1.3.2"
description = "Utility to detect blocking calls in the async event loop"
readme = "README.md"
keywords = ["async", "block", "detect", "event loop", "asyncio"]
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a097cee

Please sign in to comment.