简体   繁体   English

如何异步运行sublime text3插件命令

[英]How to run sublime text3 plugin command asynchronously

I am writing sublime text3 plugin.(python3) 我正在编写sublime text3插件。(python3)

I want to make a WindowCommand which opens files and does somethings on files then saves and closes the views. 我想制作一个WindowCommand,它可以打开文件并对文件执行某些操作,然后保存并关闭视图。

However, when I open a file at WindowCommand, view is not opened until the plugin is finished. 但是,当我在WindowCommand中打开文件时,在插件完成之前不会打开视图。

It looks like WindowCommand blocks main sublime thread. 它看起来像WindowCommand阻止主崇高线程。

So I can't do anything on the opened views. 因此,我无法对打开的视图执行任何操作。

When I try to wait until the view is opened using 'is_loading()' API, it waits forever because view has not been opened until the command has finished 当我尝试等到使用'is_loading()'API打开视图时,它会一直等待,因为直到命令完成后才打开视图

Anyone can give any tips or solution? 任何人都可以提供任何提示或解决方案?

Thank you 谢谢

If the plugin is opening, editing, saving, and closing plugins, why not just write to the file. 如果插件正在打开,编辑,保存和关闭插件,为什么不直接写入文件。 It would save you the overhead of managing all the views. 这样可以节省管理所有视图的开销。 Anyways, you will need to do some threading. 无论如何,您将需要进行一些线程化。 Take a look at http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-text-2-plugin/ . 看看http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-text-2-plugin/ It's written for ST2, but the same concepts apply, though the libraries changed between python2 and python 3. Step 4 begins talking about threading. 它是为ST2编写的,但是相同的概念适用,尽管库在python2和python 3之间进行了更改。第4步开始讨论线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM