예제 #1
0
	def on_button_pressed(self, event):
		print "Will start long task"
		workerthread.executeInWorkerThread(
			self.someLongWorkingFunction
			#You do not need lambda, if function does not take parameters
			)
		print "Will also post decorated logn working function"
		self.someLongWorkingFunctionDecoratedForWorkerThread(self)
예제 #2
0
		time.sleep(2)
		print "\tprintFromWorkerThread %s Sleeping"%message
		i+=1
	print "\tprintFromWorkerThread %s After sleep. Finished"%message
	return message
	
	
def processResult(message):
	print "*"*30
	print "RESULT: received message:%s"%message
	print "*"*30
	
	
if __name__ == '__main__':
	workerthread.executeInWorkerThread(
		lambda: printFromWorkerThread2("Message 1"),
		result_callback = processResult
	)
	print "Message 1 task was posted to worker thread"
	
	workerthread.executeInWorkerThread(
		lambda: printFromWorkerThread2("Message 2"),
		delay_ms = 15000, #This should start approx 5 sec after finish of the first task
		result_callback = processResult
	)
	print "Message 2 task was posted to worker thread"
	
	i=0
	while i<6:
		time.sleep(3)
		print "main thread sleeping"
		i+=1
예제 #3
0
	def on_button_pressed(self, event):
		print "Will start long task"
		workerthread.executeInWorkerThread(
			someLongWorkingFunction
			#You do not need lambda, if function does not take parameters
			)
예제 #4
0
sys.path.append(os.path.realpath(".."))
import workerthread

def printFromWorkerThread(message):
	print "\tprintFromWorkerThread %s Before sleep"%message
	i=0
	while i<5:
		time.sleep(2)
		print "\tprintFromWorkerThread %s Sleeping"%message
		i+=1
	print "\tprintFromWorkerThread %s After sleep. Finished"%message
	
	
if __name__ == '__main__':
	workerthread.executeInWorkerThread(
		lambda: printFromWorkerThread("Message 1")
	)
	print "Message 1 task was posted to worker thread"
	
	workerthread.executeInWorkerThread(
		lambda: printFromWorkerThread("Message 2")
	)
	print "Message 2 task was posted to worker thread"
	
	i=0
	while i<6:
		time.sleep(3)
		print "main thread sleeping"
		i+=1
	print "Main thread sleep finished. Will wait for workerthread to finish"