Multiple independent embedded Python Interpreters on multiple operating system threads invoked from C/C++ program

前端 未结 1 1038
小蘑菇
小蘑菇 2020-12-08 20:21

Embedding Python interpreter in a C/C++ application is well documented. What is the best approach to run multiple python interpreter on multiple operating system threads (i.

相关标签:
1条回答
  • 2020-12-08 21:09

    It's not exactly an answer to your question, but you could use separate processes instead of threads, then the problems should vanish.

    Pros:

    • No need hacking python (and making sure the result works in all of the intended cases)
    • Probably less development effort overall
    • Easy upgrading to new python versions
    • Clearly defined interfaces between different processes, thus easier to get right and debug

    Cons:

    • Maybe slightly more overweight, depending on your platform (relatively light-weight processes on linux)

    If you use shared memory for IPC, your resulting application code shouldn't differ too much from what you'd get with threads.

    Given that some people are arguing you should always use processes over threads, I'd at least consider it as an alternative if it fits your constraints in any way.

    0 讨论(0)
提交回复
热议问题