uqfoundation / pathos

parallel graph management and execution in heterogeneous computing
http://pathos.rtfd.io
Other
1.39k stars 89 forks source link

Infinite recursive call of process in c++ #173

Open linssswww opened 5 years ago

linssswww commented 5 years ago

I used multiprocessing in c++ , but its difference between c++ calling and python calling. my c++ code: #include

include

include

include

include

//#include<opencv2/opencv.hpp>

include "opencv2/opencv.hpp"

include <numpy/arrayobject.h>

using namespace std; using namespace cv; int main(int argc, char argv[]) { printf("enter cpp main\n"); Py_Initialize(); if (!Py_IsInitialized()) return false; PyRun_SimpleString("import sys"); PyRun_SimpleString("sys.path.append('C:////Users////Administrator////Desktop////fpcb_interface////fpcb_interface////Detectron-master-mutiprocess')"); PyRun_SimpleString("sys.path.append('C:////Users////Administrator////Desktop////fpcb_interface////fpcb_interface////Detectron-master-mutiprocess////tools')"); //vs 的工作目录在 //Detection(); PyObject pModule = NULL; PyObject pFunc = NULL; pModule = PyImport_ImportModule("muti_infer"); //import infer_simple PyObject pDict = PyModule_GetDict(pModule); // PyObject *pyFunc = PyObject_GetAttrString(pModule, "muti_work_init"); //函数指针的入口地址 PyObject_CallObject(pyFunc, NULL); Py_Finalize(); getchar(); return 0; } ` my python file "muti_infer.py":

`from multiprocessing import Pipe from multiprocessing import Process from multiprocessing import freeze_support

def worker(): while True: print("subprocess !!!") pass

def muti_work_init(): w = Process(target = worker) w.start() print("finish muti_work_init")

if name == 'main': muti_work_init()`

This is consle output: enter cpp main finish muti_work_init enter cpp main finish muti_work_init enter cpp main finish muti_work_init enter cpp main finish muti_work_init enter cpp main finish muti_work_init enter cpp main finish muti_work_init enter cpp main finish muti_work_init enter cpp main finish muti_work_init enter cpp main finish muti_work_init enter cpp main finish muti_work_init enter cpp main finish muti_work_init

I just called muti_work_init for one times, why it was called for many times. I found some way which add freez_support in python code, but I dont know how to do in c++