Sublime Forum

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

#1

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:
github.com/frou/GoFeather/blob/ … nds.py#L15

Here is the build system it calls:
github.com/frou/GoFeather/blob/ … lime-build

0 Likes

#2

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.

0 Likes

#3

Alright. Thanks :smile:

0 Likes