-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
37 lines (28 loc) · 689 Bytes
/
example.py
File metadata and controls
37 lines (28 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from contextlib import contextmanager, ExitStack
@contextmanager
def null_context():
yield
def some_cb(*a, **kw):
pass
@contextmanager
def inner_context():
stack = ExitStack()
with stack:
stack.enter_context(null_context())
stack.callback(some_cb, 10, "hi", answer=42)
yield "inner"
@contextmanager
def outer_context():
with inner_context() as inner:
yield "outer"
def example():
with outer_context():
yield
def call_example():
yield from example()
gen = call_example()
next(gen)
import stackscope
stack = stackscope.extract(gen)
print(stack)
print(stack.frames[1].contexts[0].inner_stack.frames[0].contexts[0])