在配置sublimeREPL后,偶尔会遇到运行假死的情况,程序长时间无响应。尤其是输出较大文本时。
翻了SublimeREPL的github项目,发现不少人也遇到这问题,是插件本身的一个bug,官方还没得到完美解决。
我们有以下两种解决方案:
1、如果还需要一直用sublimeREPL,参考了https://github.com/wuub/SublimeREPL/issues/469,可以用以下临时方案:
找到文件(Packages\SublimeREPL\sublimerepl.py) 里面的handle_repl_output() . 修改成下面的内容:
def handle_repl_output(self):
"""Returns new data from Repl and bool indicating if Repl is still
working"""
if self.repl.apiv2:
try:
while True:
packet = self._repl_reader.queue.get_nowait()
if packet is None:
return False
self.handle_repl_packet(packet)
except queue.Empty:
return True
else:
try:
packet = self._repl_reader.queue.get_nowait()
if packet is None:
return False
for _ in xrange(1000):
try:
packet += self._repl_reader.queue.get_nowait()
except queue.Empty: break
self.handle_repl_packet(packet)
return True
except queue.Empty:
return True
2、如果并不需要在命令行做过多交互,可以放弃使用sublimeREPL,切换到默认的python运行环境就行了。参考https://www.cnblogs.com/huluwahaha/p/7503930.html
解决方法:
默认有一个python编译版本,如下图,选择即可。
如果没有的话,打开sublime -> tools -> build system ->new build system,在打开的新tab页面添加如下内容:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
前提是“python”是可执行命令,不然要输入python的完整可执行路径。
然后Ctrl+s保存到目录(Sublime Text3/Packages/User,保存时的默认目录),可任意命名,后缀名不能更改。
然后在tools→build system中选择文件的名称。
通过Ctrl+b命令即可运行Python文件。