@@ -961,6 +961,40 @@ Execute the provided string in the identified interpreter.\n\
961
961
\n\
962
962
(See " MODULE_NAME ".exec()." );
963
963
964
+ static PyObject *
965
+ interp_run_func (PyObject * self , PyObject * args , PyObject * kwds )
966
+ {
967
+ static char * kwlist [] = {"id" , "func" , "shared" , NULL };
968
+ PyObject * id , * func ;
969
+ PyObject * shared = NULL ;
970
+ if (!PyArg_ParseTupleAndKeywords (args , kwds ,
971
+ "OO|O:" MODULE_NAME ".run_func" , kwlist ,
972
+ & id , & func , & shared )) {
973
+ return NULL ;
974
+ }
975
+
976
+ PyCodeObject * code = convert_code_arg (func , MODULE_NAME ".exec" ,
977
+ "argument 2" ,
978
+ "a function or a code object" );
979
+ if (code == NULL ) {
980
+ return NULL ;
981
+ }
982
+
983
+ if (_interp_exec (self , id , (PyObject * )code , shared ) < 0 ) {
984
+ return NULL ;
985
+ }
986
+ Py_RETURN_NONE ;
987
+ }
988
+
989
+ PyDoc_STRVAR (run_func_doc ,
990
+ "run_func(id, func, shared=None)\n\
991
+ \n\
992
+ Execute the body of the provided function in the identified interpreter.\n\
993
+ Code objects are also supported. In both cases, closures and args\n\
994
+ are not supported. Methods and other callables are not supported either.\n\
995
+ \n\
996
+ (See " MODULE_NAME ".exec()." );
997
+
964
998
965
999
static PyObject *
966
1000
object_is_shareable (PyObject * self , PyObject * args , PyObject * kwds )
@@ -1030,6 +1064,8 @@ static PyMethodDef module_functions[] = {
1030
1064
METH_VARARGS | METH_KEYWORDS , exec_doc },
1031
1065
{"run_string" , _PyCFunction_CAST (interp_run_string ),
1032
1066
METH_VARARGS | METH_KEYWORDS , run_string_doc },
1067
+ {"run_func" , _PyCFunction_CAST (interp_run_func ),
1068
+ METH_VARARGS | METH_KEYWORDS , run_func_doc },
1033
1069
1034
1070
{"is_shareable" , _PyCFunction_CAST (object_is_shareable ),
1035
1071
METH_VARARGS | METH_KEYWORDS , is_shareable_doc },
0 commit comments