Registry / testing / blockbuster

blockbuster

JSON →
library1.5.27pypypi✓ verified 24d ago

Blockbuster is a Python package designed to detect and prevent blocking calls within an asynchronous event loop. It's particularly useful during testing to ensure asynchronous code doesn't inadvertently perform blocking operations, which can cause performance bottlenecks. It works by monkey-patching common blocking functions and raising a `BlockingError` if called within an `asyncio` event loop. It currently only detects `asyncio` event loops and is tested with CPython.

pip install blockbuster
INSTALL
IMPORT
SIG · BLOCKBUSTER
B
blockbuster
testingpythonv1.5.27
Install
2.5s avg
Import
231ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.5.27 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.230s · 19.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.232s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

blockbuster_ctx
from blockbuster import blockbuster_ctx
Context manager to activate blocking call detection.
BlockingError
from blockbuster import BlockingError
The exception raised when a blocking call is detected.

This quickstart demonstrates how to use `blockbuster_ctx` to detect blocking calls within an `asyncio` event loop. It runs an `async` function that intentionally calls `time.sleep()`, which is a blocking operation. When `blockbuster_ctx` is active, this call will raise a `BlockingError`. The second part shows the same blocking call without `blockbuster` activated, which completes without error, highlighting the utility of the library.

import asyncio import time from blockbuster import blockbuster_ctx, BlockingError async def main(): print("Running async task with blockbuster (should fail on time.sleep)...") try: with blockbuster_ctx(): # This is a blocking call and should raise BlockingError time.sleep(0.1) print("This line should not be reached if blocking call is detected.") except BlockingError as e: print(f"Caught expected BlockingError: {e}") except Exception as e: print(f"Caught unexpected error: {e}") print("\nRunning async task without blockbuster (should complete)...") try: # This will complete without error time.sleep(0.1) print("Blocking call completed without blockbuster activated.") except BlockingError as e: print(f"Caught BlockingError (unexpected): {e}") if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
breakingBreaking changes, such as new rules, may be introduced between minor versions. It is recommended to constrain the Blockbuster version on the minor version (e.g., `blockbuster>=1.5.0,<1.6`).
fix
Always pin to a specific minor version or range for stability, e.g., `pip install 'blockbuster<X.Y'` where X.Y is your current major.minor version.
affects: All versions
gotchaBlockbuster currently only detects `asyncio` event loops. It does not provide detection for other asynchronous frameworks.
fix
Ensure your project exclusively uses `asyncio` or understand that other async contexts will not be monitored. For other frameworks, consider alternative detection mechanisms or custom rules.
affects: All versions
gotchaBlockbuster is primarily tested with CPython. While it might work with other Python implementations, its functionality relies on the ability to monkey-patch functions with `setattr`, which may not be consistently available or behave identically across all interpreters.
fix
Use Blockbuster predominantly with CPython. If using other Python implementations (e.g., PyPy, Jython), thoroughly test its behavior and be prepared for potential inconsistencies.
affects: All versions
gotchaBlockbuster may not detect blocking calls made by third-party libraries that wrap C libraries instead of using standard Python framework methods for I/O.
fix
For such cases, you may need to add custom rules to Blockbuster's configuration during your test setup to specifically target the blocking functions used by those C-wrapped libraries. Contributions to the core project for common libraries are also welcome.
affects: All versions
Errors
Common errors & fixes
blockbuster.blockbuster.BlockingError: Blocking call to sleep (<module 'time' (built-in)>)
Your asynchronous code is performing a synchronous (blocking) operation, such as `time.sleep()`, within an `asyncio` event loop while `blockbuster` is active.
fix
Replace the blocking call with its asynchronous equivalent (e.g., `await asyncio.sleep(1)`) or run the blocking operation in a separate thread using `await asyncio.to_thread(your_blocking_function, *args)`.
ImportError: cannot import name 'Blockbuster' from 'blockbuster'
The user is attempting to import the `BlockBuster` class with incorrect casing (e.g., 'Blockbuster' instead of 'BlockBuster') or a non-existent name from the `blockbuster` package.
fix
Ensure the correct casing is used for the class name: `from blockbuster import BlockBuster`.
blockbuster.blockbuster.BlockingError: Blocking call to os.listdir
A third-party library or your code is performing a blocking file system operation (like `os.listdir`) within an `asyncio` event loop while `blockbuster` is active.
fix
Refactor the code to use asynchronous file I/O if available, wrap the blocking call in `await asyncio.to_thread(os.listdir, path)` to run it in a separate thread, or, if the blocking call is expected and safe, add a custom rule to `BlockBuster` to ignore it.
blockbuster.blockbuster.BlockingError: Blocking call to socket.socket.accept
A network operation, specifically accepting a socket connection, is being performed synchronously within an `asyncio` event loop.
fix
Use `asyncio`'s built-in asynchronous networking capabilities or wrap the blocking `socket.accept()` call with `await asyncio.to_thread(socket.accept)`.
Upgrade
Version history
1.5.27latest on PyPI · released Aug 17, 2026
Audit
Dependencies
forbiddenfruitrequiredUsed for monkey-patching CPython immutable builtin functions and methods.
PythonrequiredRequires Python version >=3.8.
Agent activity
15 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
blockbuster — pip install blockbuster · libregistry