What operations in the Sublime Text 2 API are thread safe?

In the Sublime Text 3 API, all operations are thread safe :

Threading

All API functions are thread safe ...

but in Sublime Text 2 API this is not the case. Since I personally learned of my displeasure , some operations will fail in an unpredictable and OS-dependent way when called from threads other than the main thread with the message

RuntimeError: main thread needs to be called, consider using sublime.set_timeout (function, timeout)

I can track one reliance on thread safety in the Sublime Text 2 docs (emphasis mine):

set_timeout (callback, delay)

Call this callback after the specified delay (in milliseconds). Equal delay callbacks will run in the order in which they were added. It is safe to call setTimeout from multiple threads.

But translating everything into set_timeout

calls is tedious and difficult to understand. Are there any other API methods that I can safely use from the main thread if I want to support Sublime Text 2 or set_timeout

only use one way?

+3


source to share


1 answer


According to the Sublime Text 3 Tailoring Guide, the only thread safe method in Sublime Text 2 is set_timeout

:



In Sublime Text 2, only the method set_timeout

was thread safe. In Sublime Text 3, every API method is thread safe.

+5


source







All Articles