Last active
August 12, 2017 20:16
-
-
Save Sulkar/29ee9b79f5b4e85d840df7b90b068da9 to your computer and use it in GitHub Desktop.
[python] multithread example to not freeze/not block AppJar when sleep function is called
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
# | |
# Multithread AppJar example | |
import threading, time | |
from appJar import gui | |
def btn_normal(btnName): | |
app.addLabel("l1", "Label 1") | |
#call sleep Function for Label 2 in main thread | |
sleepFunction(3) | |
app.addLabel("l2", "Label 3") | |
def btn_thread(btnName): | |
app.addLabel("l1", "Label 1") | |
#call sleep Function for Label 2 in seperate thread | |
threadObj = threading.Thread(target=sleepFunction, args=[3]) | |
threadObj.start() | |
app.addLabel("l2", "Label 3") | |
def sleepFunction(_sleepTime): | |
time.sleep(_sleepTime) | |
app.addLabel("l3", "Label 2 sleep") | |
# AppJar gui | |
app = gui("Test Form") | |
app.addNamedButton("Start with one thread", "btn1", btn_normal) | |
app.addNamedButton("Start with two threads", "btn2", btn_thread) | |
app.go() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Two buttons: