Embedded Python and multiprocessing on Windows?

applemask at gmail.com applemask at gmail.com
Fri Aug 10 15:06:39 EDT 2018


On Friday, August 10, 2018 at 2:28:45 AM UTC-4, Léo El Amri wrote:
> That may be something simple: Did you actually protected the entry-point
> of your Python script with if __name__ == '__main__': ?

That was my first thought too; the script technically doesn't have top-level code, so I figured I didn't need a main catch. Just to be sure, I added one and it still didn't resolve. The function in the second script that correctly multiprocesses doesn't have a main (or top level code) either.

I'm wondering if it's related to how I call the script in code. I'm using boost.python, but I'm not sure I'm doing it entirely correctly (the boost.python documentation is weirdly hazy on the semantics of calling script files, but is drowning in examples of how to execute hard-coded lines, which seems insane to me; who on earth would go to the trouble to embed an interpreter to run hardcoded Python strings?)

Anyway, those lines look like this:

py::object main_module = py::import("__main__");
py::dict global = py::extract<dict>(main_module.attr("__dict__"));
py::object result = py::exec_file(scriptName, global, global);
py::object runner = global["EntryFunction"];
retval = py::extract<int>(runner(py::ptr(taskPtr)));
// we pass a pointer to the entry function




More information about the Python-list mailing list