Created
September 18, 2017 23:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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