Concurrent Swift and Python interop

I've been looking at python/swift interop and from what I've been able to piece together from github, Python.import calls dlopen on the users path to python. Some questions I have are:

  • Does dlopen spin up an actual Python interpreter? I always assumed it just loads a library to call into.
  • Do multiple calls to Python.import spin up multiple interpreters or simple load a library?
  • How does this interface with concurrency in Swift? Will I be using separate interpreters per thread or a single global one? What are the implications here?

Thanks!

dlopen loads the Python runtime library of a particular version (selected via PythonLibrary.useVersion(_:_:)), without running an actual Python interpreter.

It loads a Python module by calling PyImport_ImportModule(_:) without creating new interpreters.

Thanks rxwei,

Was just reading through https://docs.python.org/2.0/api/threads.html
So if I'm interpreting this documentation correctly there is 1 interpreter and then a global lock that threads have to acquire when they want to run python.

without running an actual Python interpreter.

Does the interpreter then only run when dynamic calls are made to PythonObjects? Does every call to a PythonObject have to acquire the lock individually?