0

I am embedding Python3 interpreter into Cocoa app. My app needs multiple separated Python execution contexts, so I need to spawn multiple interpreters.

Python3 manual offers at least two ways to spawn execution context.

  • PyInterpreterState_New
  • Py_NewInterpreter

What are them and which should I use to create completely separated python context? (like a system process)

eonil
  • 83,476
  • 81
  • 317
  • 516

1 Answers1

2

Newbie to embedding Python, but looking at the docs, it seems that Py_NewInterpreter is the way to go. PyInterpreterState_New simply creates a new interpreter state object, while Py_NewInterpreter creates a new sub-interpreter. A sub-interpreter mostly behaves the same as a seperate process, except with some caveats.

Ramchandra Apte
  • 4,033
  • 2
  • 24
  • 44
  • 1
    Yes, and internally `Py_NewInterpreter` calls `PyInterpreterState_New` as the first item before continuing to associate a new `PyThreadState` with the new interpreter and set up the initial interpreter modules. – Austin Phillips Oct 16 '13 at 22:36