Thread lag

Asterix asterix at lagaule.org
Sat Apr 25 20:14:54 CEST 2009


Hi,

Here is a small class I use in my GTK application, to do some job in a
thread.:

class ThreadInterface:
   def __init__(self, func, func_args, callback, callback_args):
      '''Call a function in a thread and then call callback'''
      def thread_function(func, func_args, callback, callback_args):
         print 'func start'
         output = func(*func_args)
         gobject.idle_add(callback, output, *callback_args)
      Thread(target=thread_function, args=(func, func_args, callback,
         callback_args)).start()
      print 'thread called'

Here is the way I call the class:

def decrypt_thread(encmsg, keyID):
   # Do things
   return val1, val2)

def _on_message_decrypted(output, val):
   # blabla

ThreadInterface(decrypt_thread, [encmsg, keyID], _on_message_decrypted,
[val])


But between the time "thread called" is printed and the time "func
start" is printed, there is sometimes (it vary a lot) several seconds.

How could it be? Why thread is not started instantly? How can I improve
that?

Thanks for your help



More information about the Python-list mailing list