Repository navigation
feat: add async support for @bench decorator and bench.arecord() - #71
Merged
Merged
Conversation
- __call__ detects coroutine functions via inspect.iscoroutinefunction and returns an async def wrapper (functools.wraps preserved); sync path unchanged - MBLineProfiler raises NotImplementedError at decoration time for async funcs - bench.arecord(name) returns _AsyncContextManagerRun for use with async with - 11 new pytest-asyncio tests covering: standard fields, iterations, warmup, exception capture, MBReturnValue, MBFunctionCall, arecord, MBLineProfiler guard, and monitor thread - docs/user-guide/async.md with usage guide and timing caveat - pytest-asyncio added to test optional-dependencies; asyncio_mode = "auto"
asyncio_mode = "auto" in pyproject.toml generates a warning and is not recognised until after pytest-asyncio is loaded. In strict mode (the default in pytest-asyncio >= 0.21) async tests require an explicit mark. Adding @pytest.mark.asyncio to each async test makes them work with both auto and strict mode without relying on the config key.
Replaces the manually maintained pip install list with pip install -e .[test] so CI automatically picks up any future test dependency changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@benchnow detectsasync deffunctions viainspect.iscoroutinefunctionand returns a trueasync defwrapper —await decorated_fn()works in any async framework; the sync path is completely unchangedbench.arecord(name)returns_AsyncContextManagerRunforasync withblocks, mirroringbench.record()for sync codeMBLineProfilerraisesNotImplementedErrorat decoration time when applied to an async function (line profiling of coroutines is unsupported)iterations, andwarmupbehave identically to the sync pathpytest-asynciotests;pytest-asyncioadded to test dependencies withasyncio_mode = "auto"docs/user-guide/async.mdcovering usage, timing caveat, andMBLineProfilerincompatibility