-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debug mechanism #5
Comments
Adding a class property (or instance property) of asyncinject/asyncinject/__init__.py Lines 81 to 84 in 28fb38f
|
Prototype: diff --git a/asyncinject/__init__.py b/asyncinject/__init__.py
index 8323b67..bf78932 100644
--- a/asyncinject/__init__.py
+++ b/asyncinject/__init__.py
@@ -50,6 +50,8 @@ def _make_method(method):
class AsyncInject:
+ _debug_asyncinject = True
+
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
# Decorate any items that are 'async def' methods
@@ -82,6 +84,8 @@ async def resolve(instance, names, results=None):
if results is None:
results = {}
+ debug = getattr(instance, "_debug_asyncinject", False)
+
# Come up with an execution plan, just for these nodes
ts = graphlib.TopologicalSorter()
to_do = set(names)
@@ -101,8 +105,13 @@ async def resolve(instance, names, results=None):
plan.append(node_group)
ts.done(*node_group)
+ if debug:
+ print("\nResolving {} in {}".format(names, instance))
+
for node_group in plan:
awaitable_names = [name for name in node_group if name in instance._registry]
+ if debug:
+ print(" ", awaitable_names)
awaitables = [
instance._registry[name](
instance,
Running with
|
Even simpler: |
Add a mechanism which shows exactly how the class is executing, including which methods are running in parallel. Maybe even with a very basic ASCII visualization? Then use it to help illustrate the examples in the README, refs #4.
The text was updated successfully, but these errors were encountered: