1 #pragma once 2 3 #include <c10/core/impl/PyInterpreter.h> 4 #include <c10/macros/Export.h> 5 6 namespace c10::impl { 7 8 struct C10_API PythonDispatcherTLS { 9 static void set_state(PyInterpreter* state); 10 static PyInterpreter* get_state(); 11 static void reset_state(); 12 }; 13 14 struct C10_API DisablePythonDispatcher { DisablePythonDispatcherDisablePythonDispatcher15 DisablePythonDispatcher() : old_(PythonDispatcherTLS::get_state()) { 16 PythonDispatcherTLS::set_state({}); 17 } ~DisablePythonDispatcherDisablePythonDispatcher18 ~DisablePythonDispatcher() { 19 PythonDispatcherTLS::set_state(old_); 20 } 21 PyInterpreter* old_; 22 }; 23 24 } // namespace c10::impl 25