Sublime Forum

Opening an exe on a separate thread

#1

Good day everyone

I’m making a sublime text plugin, it opens a separate application via subprocess popen and send the output back to sublime.

Everything works as expected, but it’s blocking the sublime text window while it’s open, is there I can launch the separate exe as non-blocking?

I did try using “sublime.set_timeout_async”, which launched the app and didn’t block sublime, but it didn’t look like I could capture the output, and anytime I executed something, or closed my app, it would auotmatically repoen
I have something like this:

output= sublime.set_timeout_async(lambda: self.run_command_line([arg1,arg2]),0)
def run_command_line(self,args):
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
out= proc.communicate()[0].decode(‘utf-8’)
return out

Basically, I’d like to launch my exe (as a text or window command), and then leave it open, select text, press a button in my separate application, it sends information back, replaces my current text, and keep that process going till I close the app

1 Like

#2

For something like that, you need to run your program in a separate process; running something that never exits in the main thread will block the UI, and running it in the async thread will block the async thread (i.e. no async events or anythign else waiting on such a timeout will fire until your command exits).

An example of how to do that can be found here: https://github.com/STealthy-and-haSTy/SublimeScraps/blob/master/plugins/pipe_text.py

0 Likes

#3

Ah! Thank you so much, I’ll peruse that as reference!

0 Likes