如标题所述,有没有办法做这样的事情:
def call_back():
if called inside context:
print("running in context")
else:
print("called outside context")
这将导致:
with CTM() as context:
call_back()
call_back()
>>> "running in context"
>>> "called outside context"