Python Forum
PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop (/thread-38207.html)



PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop - Xeno - Sep-15-2022

//C++
string path = "C:/PycharmProjects/testProject/test/main.py"
FILE* fp = NULL;
errno_t fp_err = fopen_s(&fp, path.c_str(), "r");
if (fp == NULL)
{
     cout << "[PyScript] Error opening file: " << path << endl;
     return false;
}
// after calling this, the python main class __init__ will loop forever
int re = PyRun_SimpleFile(fp, path.c_str());
fclose(fp);
import ctypes
from multiprocessing import Manager
class TestClass:
    def __init__(self, count):
        self.count = count
        # python will loop here forever, without it the class will run fine
        self.sync_manager = Manager()      
How do I get around this issue on multiprocessing when calling the calss from c++?


RE: PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop - woooee - Sep-16-2022

How are you using self.sync_manager? A multiprocessing Manager is used to create a common list, dictionary, etc. https://pymotw.com/3/multiprocessing/communication.html#managing-shared-state


RE: PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop - Xeno - Sep-19-2022

i am using the sync_manager to stop other process that is running

self.stopping = self.sync_manager.Value('b', False)

however it seems the issue happens even without using the sync_manager

all I need to create the Mangaer() without actually using it. this loop will start. not creating the Manager() everything will run fine.