Is there a way to know whether no objects out of `if __name__=="__main__"`

Hi, experts
As we know, main module in spawned processes is an empty module in fact. So, python multiprocessing fails in notebook on Windows in general, unless the code is like below, that is, not codes between imports and if __name__== "__main__"

import XXX
import YYY
from ZZZ import dosomething
if __name__ == "__main__":
dosomething()

Is there an elegant way to know this situation? Thus, dosomething() can spawn new processes without exception.