本文整理汇总了C++中Py_SetProgramName函数的典型用法代码示例。如果您正苦于以下问题:C++ Py_SetProgramName函数的具体用法?C++ Py_SetProgramName怎么用?C++ Py_SetProgramName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Py_SetProgramName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ada_py_initialize_and_module
PyObject*
ada_py_initialize_and_module(char* program_name, char* name) {
PyObject* module;
PyObject* imported;
user_module_name = strdup(name);
#if PY_MAJOR_VERSION >= 3
user_module.m_name = user_module_name;
Py_SetProgramName ((wchar_t*)program_name);
#else
Py_SetProgramName (program_name);
#endif
PyImport_AppendInittab(user_module_name, init_user_module);
Py_InitializeEx(0);
// Initialize the prompt if needed
PyObject* prompt = PySys_GetObject ("ps1");
if (prompt == NULL) {
prompt = PyUnicode_FromString (">>> ");
PySys_SetObject ("ps1", prompt);
Py_DECREF (prompt);
}
prompt = PySys_GetObject ("ps2");
if (prompt == NULL) {
prompt = PyUnicode_FromString ("... ");
PySys_SetObject ("ps2", prompt);
Py_DECREF (prompt);
}
// Make the user's module visible to scripts. We cannot use
// PyImport_ImportModule, which imports the module but doesn't add
// it to the global dictionary and as such it is not visible to
// user scripts.
imported = PyImport_ImportModule(name);
if (imported == NULL) {
printf ("Could not import module %s", name);
return NULL;
}
// Import 'sys', which is needed for instance in Set_Default_Console
// to get access to the default value
PyRun_SimpleString("import sys\n");
char* command = (char*)malloc(9 + strlen(name));
strcpy (command, "import ");
strcat (command, name);
strcat (command, "\n");
PyRun_SimpleString(command);
free (command);
return imported;
};
示例2: LogInfo
void PyInviwo::initPythonCInterface(Python3Module* module) {
if (isInit_) return;
isInit_ = true;
LogInfo("Python version: " + toString(Py_GetVersion()));
wchar_t programName[] = L"PyInviwo";
Py_SetProgramName(programName);
Py_InitializeEx(false);
if (!Py_IsInitialized()) {
LogError("Python is not Initialized");
return;
}
PyEval_InitThreads();
importModule("builtins");
importModule("sys");
dict_ = PyImport_GetModuleDict();
registerPyModule(&Inviwo_Internals_Module_Def, "inviwo_internal");
registerPyModule(&Inviwo_Module_Def, "inviwo");
addModulePath(module->getPath() + "/scripts");
initOutputRedirector(module);
}
示例3: do_pyinit
void do_pyinit() {
#ifdef EXPOSE_PERL
PyObject *main_dict;
PyObject *perl_obj;
PyObject *dummy1 = PyString_FromString(""),
*dummy2 = PyString_FromString("main");
#endif
/* sometimes Python needs to know about argc and argv to be happy */
int _python_argc = 1;
char *_python_argv[] = {
"python",
};
Py_SetProgramName("python");
Py_Initialize();
PySys_SetArgv(_python_argc, _python_argv); /* Tk needs this */
#ifdef EXPOSE_PERL
/* create the perl module and add functions */
initperl();
/* now -- create the main 'perl' object and add it to the dictionary. */
perl_obj = newPerlPkg_object(dummy1,dummy2);
main_dict = PyModule_GetDict(PyImport_AddModule("__main__"));
PyDict_SetItemString(main_dict, "perl", perl_obj);
Py_DECREF(perl_obj);
Py_DECREF(dummy1);
Py_DECREF(dummy2);
#endif
}
示例4: XOJ_CHECK_TYPE
void PythonRunner::initPython() {
XOJ_CHECK_TYPE(PythonRunner);
if (this->pythonInitialized) {
return;
}
Py_SetProgramName("Xournal");
Py_Initialize();
PyXournal_initPython(this->control);
char buffer[512] = { 0 };
const char * path = getcwd(buffer, sizeof(buffer));
g_return_if_fail(path != NULL);
PyObject * sysModule = PyImport_ImportModule("sys");
g_return_if_fail(sysModule != NULL);
PyObject * pathObject = PyObject_GetAttrString(sysModule, "path");
g_return_if_fail(pathObject != NULL);
String p = path;
p += "/../testing";
PyObject * ret = PyObject_CallMethod(pathObject, "append", "s", p.c_str());
Py_DecRef(ret);
p = path;
p += "/testing";
ret = PyObject_CallMethod(pathObject, "append", "s", p.c_str());
Py_DecRef(ret);
Py_DecRef(pathObject);
Py_DecRef(sysModule);
}
示例5: embed_init_python
void embed_init_python(void)
{
FENTER;
#ifndef PYTHON_SO_LIB
#error "Python version needs passing in with -DPYTHON_SO_VERSION=libpython<ver>.so"
#else
#define PY_SO_LIB xstr(PYTHON_SO_LIB)
#endif
void *ret = dlopen(PY_SO_LIB, RTLD_LAZY | RTLD_GLOBAL);
if (!ret) {
fprintf(stderr, "Failed to find python lib %s (%s)\n", PY_SO_LIB, dlerror());
}
// Don't initialise python if already running
if (gtstate)
return;
Py_SetProgramName(progname);
Py_Initialize(); /* Initialize the interpreter */
PySys_SetArgvEx(1, argv, 0);
PyEval_InitThreads(); /* Create (and acquire) the interpreter lock */
/* Swap out and return current thread state and release the GIL */
gtstate = PyEval_SaveThread();
FEXIT;
}
示例6: _testembed_Py_Initialize
static void _testembed_Py_Initialize(void)
{
/* HACK: the "./" at front avoids a search along the PATH in
Modules/getpath.c */
Py_SetProgramName(L"./_testembed");
Py_Initialize();
}
示例7: mod_init
static int mod_init(rlm_python_t *inst)
{
int i;
static char name[] = "radiusd";
if (radiusd_module) return 0;
/*
* Explicitly load libpython, so symbols will be available to lib-dynload modules
*/
inst->libpython = dlopen("libpython" STRINGIFY(PY_MAJOR_VERSION) "." STRINGIFY(PY_MINOR_VERSION) ".so",
RTLD_NOW | RTLD_GLOBAL);
if (!inst->libpython) {
WARN("Failed loading libpython symbols into global symbol table: %s", dlerror());
}
Py_SetProgramName(name);
#ifdef HAVE_PTHREAD_H
Py_InitializeEx(0); /* Don't override signal handlers */
PyEval_InitThreads(); /* This also grabs a lock */
inst->main_thread_state = PyThreadState_Get(); /* We need this for setting up thread local stuff */
#endif
if (inst->python_path) {
PySys_SetPath(inst->python_path);
}
if ((radiusd_module = Py_InitModule3("radiusd", radiusd_methods,
"FreeRADIUS Module.")) == NULL)
goto failed;
for (i = 0; radiusd_constants[i].name; i++) {
if ((PyModule_AddIntConstant(radiusd_module, radiusd_constants[i].name,
radiusd_constants[i].value)) < 0) {
goto failed;
}
}
#ifdef HAVE_PTHREAD_H
PyThreadState_Swap(NULL); /* We have to swap out the current thread else we get deadlocks */
PyEval_ReleaseLock(); /* Drop lock grabbed by InitThreads */
#endif
DEBUG("mod_init done");
return 0;
failed:
Py_XDECREF(radiusd_module);
#ifdef HAVE_PTHREAD_H
PyEval_ReleaseLock();
#endif
Pyx_BLOCK_THREADS
mod_error();
Pyx_UNBLOCK_THREADS
radiusd_module = NULL;
Py_Finalize();
return -1;
}
示例8: main
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
initschoolboy_rsa();
return 0;
}
示例9: freopen
Pyramid::Pyramid(const char* script)
{
freopen("pyramid.log", "w", stdout);
freopen("pyramid.log", "a", stderr);
Py_SetProgramName(".\\pyramid");
Py_Initialize();
init_pyramid();
PyRun_SimpleString(
"import sys\n"
"sys.path.append('./')\n"
"sys.stderr = open('python_errors.log', 'w', 0)\n"
"sys.stdout = open('pyramid.log', 'a', 0)\n"
"import pyramid\n");
char* fn_local = new char[strlen(script)+1];
strcpy(fn_local, script);
PyObject* fp = PyFile_FromString(fn_local, "r");
if(!fp)
{
printf("Could not load mapping script '%s' for reading.\n", script);
Py_Finalize();
exit(1);
}
FILE* sfp = PyFile_AsFile(fp);
PyRun_AnyFileEx(sfp, script, 1);
delete[] fn_local;
}
示例10: python_system_init
/* Initialize Python interpreter */
static void python_system_init(lua_State *L) {
char *python_home = luaL_check_string(L, 1);
if (!Py_IsInitialized()) {
python_setnumber(L, PY_API_IS_EMBEDDED, 1); // If python is inside Lua
if (PyType_Ready(&LuaObject_Type) == 0) {
Py_INCREF(&LuaObject_Type);
} else {
lua_error(L, "failure initializing lua object type");
}
PyObject *luam, *mainm, *maind;
#if PY_MAJOR_VERSION >= 3
wchar_t *argv[] = {L"<lua_bootstrap>", 0};
#else
char *argv[] = {"<lua_bootstrap>", 0};
#endif
Py_SetProgramName(argv[0]);
Py_SetPythonHome(python_home);
Py_InitializeEx(0);
PySys_SetArgv(1, argv);
/* Import 'lua' automatically. */
luam = PyImport_ImportModule("lua_bootstrap");
if (!luam) {
lua_error(L, "Can't import lua_bootstrap module");
} else {
mainm = PyImport_AddModule("__main__");
if (!mainm) {
lua_error(L, "Can't get __main__ module");
} else {
maind = PyModule_GetDict(mainm);
PyDict_SetItemString(maind, "lua_bootstrap", luam);
Py_DECREF(luam);
}
}
}
}
示例11: rpmpythonNew
rpmpython rpmpythonNew(char ** av, uint32_t flags)
{
static char * _av[] = { "rpmpython", NULL };
#if defined(WITH_PYTHONEMBED)
int initialize = (!(flags & 0x80000000) || _rpmpythonI == NULL);
#endif
rpmpython python = (flags & 0x80000000)
? rpmpythonI() : rpmpythonGetPool(_rpmpythonPool);
if (_rpmpython_debug)
fprintf(stderr, "==> %s(%p, %d) python %p\n", __FUNCTION__, av, flags, python);
if (av == NULL) av = _av;
#if defined(WITH_PYTHONEMBED)
if (!Py_IsInitialized()) {
Py_SetProgramName((char *)_av[0]);
Py_Initialize();
}
if (PycStringIO == NULL)
PycStringIO = PyCObject_Import("cStringIO", "cStringIO_CAPI");
if (initialize) {
int ac = argvCount((ARGV_t)av);
(void) PySys_SetArgv(ac, (char **)av);
(void) rpmpythonRun(python, rpmpythonInitStringIO, NULL);
}
#endif
return rpmpythonLink(python);
}
示例12: main
int main(int argc, char **argv)
{
#if (COW_MPI)
{
int rank;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank != 0) freopen("/dev/null", "w", stdout);
printf("was compiled with MPI support\n");
}
#endif
Py_Initialize();
PySys_SetArgv(argc, argv);
Py_SetProgramName("/Users/jzrake/Work/cow/cowpy");
init_cow();
if (argc > 1) {
FILE *fp = fopen(argv[1], "r");
if (fp) {
PyRun_SimpleFileExFlags(fp, argv[1], 1, NULL);
fclose(fp);
}
else {
printf("No such file %s\n", argv[1]);
}
}
Py_Finalize();
printf("finished...\n");
#if (COW_MPI)
MPI_Finalize();
#endif
return 0;
}
示例13: main
int main(int argc, char *argv[]) {
// Set the python interpreter.
setup_python(argc, argv);
std::string filepath(argv[0]);
// Get the path to the helper script.
std::string helper_path;
size_t path_end = filepath.find_last_of('\\');
if (path_end != std::string::npos)
helper_path = filepath.substr(0, path_end + 1);
helper_path += "wbadminhelper.py";
// Configures the execution of the script to take the same
// parameters as this helper tool.
Py_SetProgramName(argv[0]);
PySys_SetArgv(argc, argv);
// Executes the helper script.
PyObject *pFileObject = PyFile_FromString(const_cast<char *>(helper_path.c_str()), "r");
PyRun_SimpleFileEx(PyFile_AsFile(pFileObject), "wbadminhelper.py", 1);
finalize_python();
return 0;
}
示例14: main
int
main(int argc, char **argv)
{
PyObject *main, *game;
PyObject *func, *args;
PyTaskletObject *process;
Py_SetProgramName(argv[0]);
Py_Initialize();
/* get the time python methods */
timemod = PyImport_ImportModule("time");
/* create a module for the game */
game = Py_InitModule("game", game_methods);
/* run the definition in main module */
main = PyImport_AddModule("__main__");
PyRun_SimpleString(python_prog); /* runs in main */
/* start the python function as a tasklet */
func = PyObject_GetAttrString(main, "everySecond");
process = PyTasklet_New(NULL, func);
Py_DECREF(func);
/* initialize the tasklet args */
args = PyTuple_New(0);
PyTasklet_Setup(process, args, NULL);
Py_DECREF(args);
/* now let's run the "game engine" */
run_game_engine();
Py_Finalize();
return 0;
}
示例15: main
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
initacc_monitor();
return 1;
}