Sublime Forum

set_timeout_async not working when inside a .sublime-package

#1

I have a plugin which at some point has this call:

sublime.set_timeout_async(lambda: self.step4_run_async(), 0)

and this does not work when my plugin is packaged in a .sublime-package. No error in the console, no nothing. Nothing happens.
I have prints all over the place and after I get to this call no print statement that’s inside self.step4_run_async() is displayed.
Any idea what’s going on? The call to

sublime.set_timeout_async(lambda: self.step4_run_async(), 0) 

works fine if my plugin is just in a folder and not in a .sublime-package

0 Likes

#2

This could be a lifecycle problem.

[quote]Plugin Lifecycle

At importing time, plugins may not call any API functions, with the exception of sublime.version(), sublime.platform(), sublime.architecture() and sublime.channel().

If a plugin defines a module level function plugin_loaded(), this will be called when the API is ready to use. Plugins may also define plugin_unloaded(), to get notified just before the plugin is unloaded.[/quote]

0 Likes

#3

It shouldn’t be. This is a window command which means that the plugin is already loaded or else you would not be able to trigger this command.

0 Likes

#4

Do you have sample code to share? Preferrably something that runs out of the box (i.e. faols for you) since I’ve never had this problem.

0 Likes

#5

The plugin bitbucket.org/demandware/entrop … ?at=master

And the file (line 96) where the problem is: bitbucket.org/demandware/entrop … mand.py-96

The weird this is that until now this has only happened twice.

  1. When I posted (and restarting Sublime didn’t helped) but I’ve modified sublime.set_timeout_async(lambda: self.step4_run_async(), 0) to sublime.set_timeout_async(lambda self=self: self.step4_run_async(), 0) and weirdly it worked for a while
  2. Yesterday happened again no matter how many times I run the command it always stopped at that line without any error or anything. (this time restarting sublime helped as it started working again after the restart)

Is there maybe a thread pool or a limited amount of threads available to set_timeout_async and it’s possible that they were all busy when my code run thus nothing happening?
(even though I only have one or two plugins and I wasn’t doing anything special then)

0 Likes

#6

I can’t reproduce your problem, but I did notice some things when looking at your code.

Try disabling your animation code and see if you can reproduce it. You are capturing a reference to the active_view, which may or may not exist when the command is run. The WindowCommand object is instantiated early, not every time you run the command. For an example of a progress indicator, see github.com/wbond/package_contro … rogress.py

Also, just FYI, you don’t need a lambda in your call. However, I don’t think this is related to your problem. It can be as simple as:

sublime.set_timeout_async(self.step4_run_async, 0)
0 Likes

#7

Hmm, I was under the impression that a new instance is called for each time the command runs…
If this is not the case then I need to rewrite the code.

0 Likes

#8

Another question then. How can I pass data from function to function? As if I need to prompt the user multiple times, and the show_input_panel only calls the callback with the returned value. How do I pass additional data from show_input_panel to show_input_panel so I have all the data that I asked from the user at the end?

0 Likes

#9

The way you are doing it now (setting values on self) should work fine.

An alternative is to pass the values as arguments to the callback. You can do this with lambdas, or functools. For example:

self.window.show_input_panel(panel_label, panel_value, functools.partial(self.step2_on_done, hostname), None, None)
0 Likes

#10

Cool, thanks.

Now I only need to wait for ST3 to be updated with a more recent version of SSL :smile:
(as right now where I connect they’ve disabled anything less than TLS1.1 and current version of Python bundled has only up to TLS1.0)

0 Likes