For the most part, people find it more productive to call C++ from Python
than the other way around.

That is: the “management” code is in Python and the core computation in C
or C++ or FORTRAN.

Keep in mind that Python has the GIL, so if you are calling into the
interpreter from a multi-processing code, it will all hit that bottleneck
anyway. Unless you are calling separate Python processes from separate C++
processes, in which case it’s hard for me to imagine that would be easier
to do (or high enough performance) than to manage your multiple processes
from Python.

And do take a look at tools that help you with the C:Python bridge: Cxx was
mentioned, and there is also Cython, Boost Python, etc.

I only have direct experience with Cython, but it does help a lot, and even
provides parallelism for tight loops.

-CHB


On Mon, Jan 6, 2020 at 1:32 AM Serhiy Storchaka <storch...@gmail.com> wrote:

> 06.01.20 00:20, hrfu...@gmail.com пише:
> > I've worked out MyCallFunction() in my actual code in the same manner
> described above, but with Py_VaBuildValue. What I did was I send all
> variadic arguments to a MyBuildValue(PyObject*, const char*, ...), the in
> the .c file, MyBuildValue will generate a va_list and pass it onto
> Py_VaBuildValue, then I force the outcome to be a tuple and pass it to
> PyObject_CallObject and it works! Nontheless, this approach seems less
> straightforward to having a PyObject_VaCallFunction, so I'm guessing it may
> have performance penalty.
>
> You should not worry much about performance penalty of creating a tuple
> if you use format string and variable arguments, because the latter have
> large overhead. In common cases using Py_VaBuildValue() should be
> enough. In performance critical code use PyObject_CallObject() or
> PyObject_Call(). Or even private C API like _PyObject_FastCallDict() on
> your risk.
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/DENARCI5XDRM26IFLJDSIO2UPMZXDYOK/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ODBYIBNTJD7B35KUJPW5BQ2JUCDYVTVW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to