Home Download Buy Blog Forum Support

Why do I need a time.sleep(...) here?

Why do I need a time.sleep(...) here?

Postby frou on Sun Apr 28, 2013 11:24 pm

I wrote a Sublime plugin to beautify Go code by calling the standard toolchain's "go fmt" tool via a Sublime build system.

After that tool has done its thing, I use Sublime's 'revert' command to reload the active view from disk in its beautified form.

That reloading picks up the changes, but only if a time.sleep(...) is inserted between running the build system and calling 'revert'. Why is that? Isn't everything supposed to be synchronous?

Here is the plugin:
https://github.com/frou/GoFeather/blob/ ... nds.py#L15

Here is the build system it calls:
https://github.com/frou/GoFeather/blob/ ... lime-build
frou
 
Posts: 47
Joined: Sun Jul 31, 2011 11:26 am

Re: Why do I need a time.sleep(...) here?

Postby skuroda on Mon Apr 29, 2013 6:35 am

Yes they run synchronously. But you are ignoring the fact work can be threaded. This would mean that work is still being done, even though the call returns. As an example, look at Package Control. When you select an action, say "Install Package", you regain control immediately. However, the command is still doing work (getting the list of packages). I would assume build systems do something similar. I believe the build system runs through a command listed in "Default/exec.py" if you want to look closer.

If you would like a more concrete example, create a simple plugin that simply sleeps for a while, then prints something to the console. Notice that this locks ST. Now, move that logic so it runs in a separate thread. Notice in this scenario you regain control of the ST, even though the "action" hasn't completed.
skuroda
 
Posts: 674
Joined: Fri Oct 05, 2012 8:11 am

Re: Why do I need a time.sleep(...) here?

Postby frou on Tue Apr 30, 2013 6:44 pm

Alright. Thanks :)
frou
 
Posts: 47
Joined: Sun Jul 31, 2011 11:26 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 4 guests

cron