Sitelet https://web.archive.org/web/20220807195626/https://github.com/LiteLDev/LiteLoaderBDS/issues/640
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python backend support #640

Open
6 tasks
yqs112358 opened this issue Aug 4, 2022 · 0 comments
Open
6 tasks

Python backend support #640

yqs112358 opened this issue Aug 4, 2022 · 0 comments
Labels
enhancement New feature or request module: LLSE LiteLoader ScriptEngine

Comments

@yqs112358
Copy link
Contributor

@yqs112358 yqs112358 commented Aug 4, 2022 •

目前遇到的问题:实例隔离

@twoone-3 正在尝试为ScriptX引入Python backend
目前遇到的问题是,为了使embedded Python支持ScriptX本身的多实例(多Engine)隔离的场景,需要对适配进行一定修改。目前的方案如下:

使用import进行多实例隔离

  • 将实现修改为:每一个Engine创建时都新建一个模块,异常处理、类型与函数注册、get、set、eval 等引擎相关操作都针对自己的模块进行
  • 在启动解释器后,每创建一个新引擎则在主解释器中import其源码文件,以达到环境隔离的目的
  • 对目前的Python backend实现进行修改可以解决问题,但是此方案本身不够优雅,存在一些问题:
    • 可能存在某些不可避免的全局数据共享,以及插件间互相影响
    • 要求加载时必须通过文件加载源码,一般的eval无法使用或需要临时文件解决
    • 无法实现引擎的按需卸载

使用Python SubInterpreter进行隔离

  • 不过目前用以适配的pybind11库未提供子解释器接口。据其文档描述,子解释器机制目前仍然存在一些问题(详见 https://pybind11.readthedocs.io/en/stable/advanced/embedding.html 底部)
  • 而且子解释器自身的提案PEP554目前看来仍然在工作之中(详见 python/cpython#76785 )
  • 可能需要等待Python 3.11或3.12等版本彻底完成并合并此feature之后才能着手进行相关尝试

其他TODO:

  • 解决多实例问题
  • namespace适配
  • 通过Unit test
  • pip(可以参考embedded nodejs)
  • 依赖目录设计(可以参考embedded nodejs)
  • MessageSystem & RemoteCall 适配
@github-actions github-actions bot added the status: pending Pending label Aug 4, 2022
@yqs112358 yqs112358 added the enhancement New feature or request label Aug 4, 2022
@yqs112358 yqs112358 changed the title Python support Python backend support Aug 4, 2022
@yqs112358 yqs112358 added the module: LLSE LiteLoader ScriptEngine label Aug 5, 2022
@Jasonzyt Jasonzyt removed the status: pending Pending label Aug 7, 2022
@Jasonzyt Jasonzyt pinned this issue Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module: LLSE LiteLoader ScriptEngine
Projects
None yet
Development

No branches or pull requests

2 participants