Sublime Forum

[Solved] set_timeout() doesn't delay before execution

#1

Here is my test code:

class test_plugin(sublime_plugin.TextCommand):
def run( self, edit, pos=None ):
print( " test_plugin")

    def clbk( ):
        print("clbk ", time.time() )
    print("before set_timeout ", time.time() )
    sublime.set_timeout( clbk(), 10000 )
    print("before after_timeout ", time.time() )

Here is my output:

test_plugin
before set_timeout 1463143387.736514
clbk 1463143387.736514
before after_timeout 1463143387.736514

set_timeout_async() has the same issue. I have seen this issue on windows and linux on build 3114 and recent dev builds.

0 Likes

#2

you are executing the clbk function immediately, and passing the output from that (None) to the set_timeout function. You need to use sublime.set_timeout( lambda: clbk(), 10000 ) or sublime.set_timeout( clbk, 10000 ) instead - either use a lambda or don’t include the parens.

1 Like

#3

Thanks for correction, it works as expected.

0 Likes

#4

Is there a way to mark this issue as resolved?

0 Likes

#5

standard practice is just to change the title of the post so that it has [Solved] at the front :slight_smile:

1 Like