Skip to content

Instantly share code, notes, and snippets.

@Sulkar
Last active August 12, 2017 20:16
Show Gist options
  • Save Sulkar/29ee9b79f5b4e85d840df7b90b068da9 to your computer and use it in GitHub Desktop.
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
#
# 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()
@Sulkar
Copy link
Author

Sulkar commented Aug 10, 2017

Two buttons:

  • btn1: normal sleep function call in one thread -> AppJar freezes until sleep function ends
  • btn2: creating a new thread in which the sleep function is called -> AppJar runs and Label2 added after the sleed funtion has finished

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment