Skip to content

Instantly share code, notes, and snippets.

@OdatNurd
Created September 18, 2017 23:37
Show Gist options
  • Save OdatNurd/9e192d8e811713423b6ced79f91e3150 to your computer and use it in GitHub Desktop.
Save OdatNurd/9e192d8e811713423b6ced79f91e3150 to your computer and use it in GitHub Desktop.
A contrived example of code in another thread communicating back to the main thread in a Sublime plugin
import sublime
import sublime_plugin
from threading import Thread
def background_work(target, value):
# We're in some anonymous thread; if we care, this makes sure that we
# execute the callback in the main thread.
sublime.set_timeout(target.result_of_operation(value), 1)
class UselessCommand(sublime_plugin.WindowCommand):
def run(self, value):
Thread(target=background_work, kwargs={
"target": self,
"value": value}).start()
def result_of_operation(self, value):
print("The async operation says the result is %s" % value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment