invokeAsynchronous

I’ve got a question about my old nemisis, the invokeAsynchronous call. Here’s what I’m trying to do: I have another function that is listening for incoming messages, and it adds the raw data to a dictionary. In this new function, I just want it to sit there spinning and check to see if there are new values in the dictionary, do something with it, and then delete the new value. Right now I’m doing it with a timer, but it really isn’t the right way.

Here’s my pseudo code:

def doAsynch():
	def copyData():
		global myDictionary
		while 1:
			k = myDictionary.keys() 
			k.sort()
			for i in k::
				#Do a bunch of stuff here
				del myDictionary[i]
	copyData()
system.util.invokeAsynchronous(doAsynch)

I do something very similar in my socket function, and it works fine, but this code locks up the GUI in the ‘while’ loop. Btw, this code is in the button press event.

Ideas on how to accomplish this? Thanks!

Not to sound more ignorant than usual, but what breaks it out of the while loop?

That’s the thing- I don’t want it to break out of the while loop. I just want it to sit there and constantly check if there are new values in the dictionary, just as my socket function works.

I thought by using invokeAsynchronous, it would run on its own thread and let the rest of the gui go on as usual, but I’m missing something.

It is locking up the GUI because of the while loop. You are spiking the CPU since the code is so fast. Your socket code works fine because it blocks and doesn’t run really fast. You either need to add a sleep inside of the loop or use a timer event script. To add a sleep do this[code]def doAsynch():
def copyData():
import time
global myDictionary
while 1:
k = myDictionary.keys()
k.sort()
for i in k::
#Do a bunch of stuff here
del myDictionary[i]

     time.sleep(2) # sleep for 2 seconds

copyData()
system.util.invokeAsynchronous(doAsynch)[/code]It is recommended to use a timer event script so you can remove the while loop. They run all the time in each client (if client side).