#pragma once #include #include #include namespace c10 { namespace impl { struct C10_API PythonDispatcherTLS { static void set_state(SafePyHandle state); static SafePyHandle get_state(); static void reset_state(); }; struct C10_API DisablePythonDispatcher { DisablePythonDispatcher() : old_(PythonDispatcherTLS::get_state()) { PythonDispatcherTLS::set_state({}); } ~DisablePythonDispatcher() { PythonDispatcherTLS::set_state(old_); } c10::SafePyHandle old_; }; } // namespace impl } // namespace c10