SublimeREPL 输出换行很怪异

2020-11-16 10:06:44 +08:00
 brucmao

F5 运行多次,每次换行还不一样

代码

class Singleton(object):

    def __init__(self):
        import time
        time.sleep(1)

    @classmethod
    def instance(cls, *args, **kwargs):
        if not hasattr(Singleton, "_instance"):
            Singleton._instance = Singleton(*args, **kwargs)
        return Singleton._instance

import threading

def task(arg):
    obj = Singleton.instance()
    print(obj)

for i in range(10):
    t = threading.Thread(target=task,args=[i,])
    t.start()

配置如下

    {
        "keys":["f5"],
        "caption":"SublimeREPL: save & Python - RUN current file",
        "command":"chain",
        "args":
        {
        "commands":[
            ["save"],
            [ "run_existing_window_command",{"id": "repl_python_run","file": "config/Python/Main.sublime-menu"}]
               ]
        }
    },
1768 次点击
所在节点    Sublime Text
5 条回复
floyda
2020-11-16 11:11:52 +08:00
不一样是你 Python 代码的问题, 和 Sublime 无关.
至于换行的问题, 这是异步导致的输出流的 Bug.
brucmao
2020-11-16 12:49:30 +08:00
@floyda #1 在 cmd 控制台运行就正常换行,不知道 sublime 能不能嵌入系统的控制台
brucmao
2020-11-16 12:51:26 +08:00
这是在 powershell 运行的效果
milkpuff
2020-11-16 16:09:03 +08:00
新建一个 Sublime Text 3\Data\Packages\Python\Python.sublime-build 文件,写入如下内容,ctrl+shift+b,就可以调用 cmd 运行脚本了
{
"shell_cmd": "python -u \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",

"env": {"PYTHONIOENCODING": "utf-8"},

"variants":
[
{
"name": "Run in Cmd",
"shell_cmd": "start cmd /c \"python \"${file}\" & pause\" ",
},
]
}
floyda
2020-11-17 13:45:19 +08:00
@brucmao
安装一个叫`Terminal`的插件, 可以在 Sublime 中快速打开 cmd 终端.
有专业的为什么不用, 嵌入的总是不尽如人意的.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/725647

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX