I have a multi-threaded program. I want to embed a python interpreter. I don’t want to use Python’s threading; I want to have multiple copies of the Python interpreter running.
- Can I do this? (That is, does Python have global variables, or is everything done with a single Python interpreter object?)
- Is there an example of a program that does this?
- If I can’t do it, my plan is to have multiple Python interpreters, each running in their own address space, and try to do something with inter-process communication. But that seems really hard.
- Or is Python multi-threaded well enough now that I can embed it multi-threaded?
Thanks.
Python’s interpreter uses global state, and as such you can only have one interpreter per process. You can try using
multiprocessingto run multiple processes, each with their own interpreter, but I’m not sure how well that would play with embedding.