Python Forum
PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop
#1
//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++?
Reply
#2
How are you using self.sync_manager? A multiprocessing Manager is used to create a common list, dictionary, etc. https://pymotw.com/3/multiprocessing/com...ared-state
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  issue with multiprocessing in embeded python otaolafr 1 325 Mar-05-2025, 06:24 PM
Last Post: deanhystad
  python script is hanging while calling a procedure in database prasanthi417 4 2,085 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  Is this a multiprocessing bug in Python - or am I doing something wrong? haimat 1 2,900 Oct-18-2023, 06:07 AM
Last Post: absalom1
  python multiprocessing help -- to extract 10 sql table into csv mg24 3 2,690 Nov-20-2022, 11:50 PM
Last Post: mg24
  python multiprocessing to download sql table mg24 5 2,825 Oct-31-2022, 03:53 PM
Last Post: Larz60+
  Python multiprocessing Pool apply async wait for process to complete sunny9495 6 11,728 Apr-02-2022, 06:31 AM
Last Post: sunny9495
  Init an indefinite number of class MathisDELAGE 9 3,822 Feb-18-2022, 07:49 PM
Last Post: deanhystad
  Calling a base class variable from an inherited class CompleteNewb 3 3,088 Jan-20-2022, 04:50 AM
Last Post: CompleteNewb
  Calling a class from a function jc4d 5 2,924 Dec-17-2021, 09:04 PM
Last Post: ndc85430
  Calling functions from within a class: PYQT6 Anon_Brown 4 6,795 Dec-09-2021, 12:40 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020