ambush
Example:
I would like to how does this Popular Package use my function.
test.py
1from main import Popular
2
3def foo():
4 print("In foo()")
5
6p = Popular()
7p.register(foo)
8p.run()
main.py
1from run import Runner
2
3
4class Popular:
5
6 def register(self, cb):
7 self.callback = cb
8
9 def run(self):
10 # some work
11 r = Runner(self.callback)
12 # some other work
run.py
1class Runner:
2
3 def __init__(self, cb):
4 cb()
test.py
1from main import Popular
2
3def foo():
4 print("In foo()")
5 from ambush import detector
6 detector()
7
8p = Popular()
9p.register(foo)
10p.run()
python test.py
Output:
Who is calling current function
==========================================================
In file:
/Users/tmp/run.py
class Runner:
# by caller function:
def __init__ in line 3
...
# actually call:
cb() # in line 4
...
Peek:
---------------------------------------------------------
def __init__(self, cb):
cb()
==========================================================