背景
Pyscripter是python下一个非常流行的开源IDE,笔者一直使用Pyscripter来来编写python脚本。
关于IDE的一些特性本文不在赘述,主要是分享一下今天遇到的一个问题。
问题描述
笔者的程序有两个模块,分别列为A 和 B,B模块是程序入口并将引入A模块的类和函数
笔者更新A模块后,在B模块中运行程序,发现调用A模块还是之前的内容,并没有更新,只有在重启Pyscripter的时候才会更新,这个给我的调试带来了很大的困难,每次都要重启让整个过程变的效率低下。
于是我决定找出问题的根本原因,是程序的bug还是设置的问题,在翻阅了Pyscripter的官方文档之后,我发现了一个关键的段落:
Remote Interpreter and Debugger
In addition to using the internal integrated Python engine, PyScripter offers you the option to use one of three remote Python engines. These remote engines run in a separate process, so, when using them, script errors should not affect the stability of PyScripter. You can select the python engine that will be active from the Python Engine submenu of the Run menu. Here is a brief explanation of the Python engine options:
Python Engines:
Internal
This Python engine is faster than the other options however if there are problems with the scripts you are running or debugging they could affect the reliability of PyScripter and could cause crashes. Another limitation of this engine is that it cannot run or debug GUI scripts nor it can be reinitialized.
Remote
This the default Python engine of PyScripter and is the recommended engine for most Python development tasks. It runs in a child process and communicates with PyScripter using rpyc. It can be used to run and debug any kind of script including GUI scripts. However if you run or debug GUI scripts you may have to reinitialize the engine after each run.
官方文档描述在使用Internal Engine的时候script有可能不能被重新初始化,我当前的Python设置的正是Internal Engine, 当我将Engine设置为Remote Engine的时候问题解决
解决方案
将Pyscripter Engine设为Remote Engine
反思心得
- 笔者之前一直以为Remote Engine是Pyscripter为未安装python编译器的开发者提供的一个远程解析器,实际上这种理解是错误的,通过官方文档的描述,我觉得Remote Engine更像是用命令行来运行Pyscripter编写的程序。
- Internal Engine对当前编辑的脚本是可以重新初始化的,所以非常适合编写单独模块,因为之前我大部分用pyscripter来编写的程序都需要送到服务器上运行(本地无运行环境),所以这个问题这么晚才发现,惭愧。
- Remote Engine的速度明显慢于Internal Engine,从官方文档中也可以找到线索,大概是因为每次都要重新加载所有py文件的原因吧。
- 在开发单独模块的时候推荐使用Internal Engine速度快,在编写多文件的程序时候一定要开成Remote Engine.
- 可能是引文安装Pyscripter的时候默认的engine是remote engine,所以google 百度了许久都无法找到类似问题的描述
以上是笔者一些浅显的认识,欢迎各位批评指点。