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
  python script is hanging while calling a procedure in database prasanthi417 4 522 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  Is this a multiprocessing bug in Python - or am I doing something wrong? haimat 1 1,192 Oct-18-2023, 06:07 AM
Last Post: absalom1
  python multiprocessing help -- to extract 10 sql table into csv mg24 3 1,402 Nov-20-2022, 11:50 PM
Last Post: mg24
  python multiprocessing to download sql table mg24 5 1,480 Oct-31-2022, 03:53 PM
Last Post: Larz60+
  Python multiprocessing Pool apply async wait for process to complete sunny9495 6 6,455 Apr-02-2022, 06:31 AM
Last Post: sunny9495
  Init an indefinite number of class MathisDELAGE 9 2,316 Feb-18-2022, 07:49 PM
Last Post: deanhystad
  Calling a base class variable from an inherited class CompleteNewb 3 1,697 Jan-20-2022, 04:50 AM
Last Post: CompleteNewb
  Calling a class from a function jc4d 5 1,829 Dec-17-2021, 09:04 PM
Last Post: ndc85430
  Calling functions from within a class: PYQT6 Anon_Brown 4 3,787 Dec-09-2021, 12:40 PM
Last Post: deanhystad
  Class variables and Multiprocessing(or concurrent.futures.ProcessPoolExecutor) Tomli 5 3,902 Nov-12-2021, 09:55 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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