Is there a way to detect if running code is being executed inside a context manager in python

33
November 13, 2019, at 3:40 PM

As the title states, is there a way to do something like this:

def call_back():
    if called inside context:
        print("running in context")
    else:
        print("called outside context")

And this would result in:

with CTM() as context:
    call_back()
call_back()
>>> "running in context"
>>> "called outside context"
READ ALSO
Predicted standard deviation values of Gaussian Processes are only within [0, 1]

Predicted standard deviation values of Gaussian Processes are only within [0, 1]

I am using the Gaussian Processes of scikit-learn to estimate behavior of a black box likelihood function f()

46
The Python Generator abstract base class doesn't impliment the necessary __del__, is this intentional?

The Python Generator abstract base class doesn't impliment the necessary __del__, is this intentional?

Generator objects in Python are required to have a close method that exists to ensure that context managers are exited and try

41
Input response is not working as I expected

Input response is not working as I expected

I am new to python an I am wondering why my code isn't working

33