Loading...
Searching...
No Matches
pyInterpreter.h File Reference

Python runtime utilities. More...

+ Include dependency graph for pyInterpreter.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

TF_API void TfPyInitialize ()
 Starts up the python runtime.
 
TF_API int TfPyRunSimpleString (const std::string &cmd)
 Runs the given string using PyRun_SimpleString().
 
TF_API boost::python::handle TfPyRunString (const std::string &cmd, int start, boost::python::object const &globals=boost::python::object(), boost::python::object const &locals=boost::python::object())
 Runs the given string using PyRun_String().
 
TF_API boost::python::handle TfPyRunFile (const std::string &filename, int start, boost::python::object const &globals=boost::python::object(), boost::python::object const &locals=boost::python::object())
 Runs the given file using PyRun_File().
 

Detailed Description

Python runtime utilities.

Definition in file pyInterpreter.h.

Function Documentation

◆ TfPyInitialize()

TF_API void TfPyInitialize ( )

Starts up the python runtime.

IMPORTANT: The GIL will NOT be held when this returns. (If Python is already initialized, the GIL will be unchanged)

The program name and arguments are set automatically. sys.argv has no arguments other than an argv[0] matching the program name.

◆ TfPyRunFile()

TF_API boost::python::handle TfPyRunFile ( const std::string &  filename,
int  start,
boost::python::object const &  globals = boost::python::object(),
boost::python::object const &  locals = boost::python::object() 
)

Runs the given file using PyRun_File().

start is Py_eval_input, Py_single_input or Py_file_input. globals and locals can be dictionaries to use when evaluating the string in python. Defaults to reusing globals from main module. If only the globals are provided, they will also be used as locals.

Starts the interpreter if necessary. Deals with necessary thread state setup.

Callers must hold the GIL before calling; see TfPyLock. This is true for any boost::python call, including constructing and destroying the default values of globals and locals. Holding the GIL will also make it safe to inspect the returned boost::python::handle.

◆ TfPyRunSimpleString()

TF_API int TfPyRunSimpleString ( const std::string &  cmd)

Runs the given string using PyRun_SimpleString().

Starts the interpreter if necessary. Deals with necessary thread state setup.

Callers are not required to hold the GIL, though of course they may.

Returns zero on success, nonzero on failure.

◆ TfPyRunString()

TF_API boost::python::handle TfPyRunString ( const std::string &  cmd,
int  start,
boost::python::object const &  globals = boost::python::object(),
boost::python::object const &  locals = boost::python::object() 
)

Runs the given string using PyRun_String().

start is Py_eval_input, Py_single_input or Py_file_input. globals and locals can be dictionaries to use when evaluating the string in python. Defaults to reusing globals from main module. If only the globals are provided, they will also be used as locals.

Starts the interpreter if necessary. Deals with necessary thread state setup.

Callers must hold the GIL before calling; see TfPyLock. This is true for any boost::python call, including constructing and destroying the default values of globals and locals. Holding the GIL will also make it safe to inspect the returned boost::python::handle.