【问题标题】:Which API should I use to create multiple Python3 interpreter instances?我应该使用哪个 API 来创建多个 Python3 解释器实例?
【发布时间】:2013-10-24 09:21:03
【问题描述】:

我将 Python3 解释器嵌入到 Cocoa 应用程序中。 我的应用需要多个独立的 Python 执行上下文,因此我需要生成多个解释器。

Python3 手册提供了至少两种生成执行上下文的方法。

  • PyInterpreterState_New
  • Py_NewInterpreter

它们是什么,我应该使用哪个来创建完全分离的 python 上下文? (类似于系统进程)

【问题讨论】:

    标签: python-3.x python-embedding


    【解决方案1】:

    嵌入 Python 的新手,但查看文档,似乎 Py_NewInterpreter 是要走的路。 PyInterpreterState_New 只是创建一个新的解释器状态对象,而Py_NewInterpreter 创建一个新的子解释器。子解释器的行为大多与单独的进程相同,除了一些caveats

    【讨论】:

    • 是的,在内部Py_NewInterpreter 调用PyInterpreterState_New 作为第一项,然后继续将新的PyThreadState 与新的解释器相关联并设置初始解释器模块。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 2022-07-05
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    相关资源
    最近更新 更多