
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"}] ] } }, 已用上Terminus https://github.com/randy3k/Terminus 配合插件Chain of Command,运行前先保存,配置如下
{ "keys":["f5"], "caption":"Terminus: save & Python", "command":"chain", "args": { "commands":[ ["save"], ["toggle_terminus_panel",{"cwd" :"${file_path:${folder}}","cmd" : [ "python","-i","$file" ],},] ] } }, 1 floyda 2020-11-16 11:11:52 +08:00 不一样是你 Python 代码的问题, 和 Sublime 无关. 至于换行的问题, 这是异步导致的输出流的 Bug. |
3 brucmao OP |
4 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\" ", }, ] } |