Thread processing

Anders J. Munch andersjm at
Thu Mar 6 11:13:10 CET 2003

"Paul Moore" <gustav at> wrote:
> I can use a Queue to have the threads notify when they have finished,
> but that means rewriting the thread procedures to do the notification,
> which isn't really what I want. 

Don't rewrite.  Wrap.

def frameworkify_threadprocedure(threadprocedure):
    def wrapped_threadprocedure(*args, **kwargs):
        threadprocedure(*args, **kwargs)
   return wrapped_threadprocedure

Now instead of 
   thread.start_new_thread(frameworkify_threadprocedure(spam), ...)

Write all the logic for collaboration with the main thread just once
in wrapped_threadprocedure, and you can keep the individual thread
procedures simple and framework agnostic.

HTH, Anders

More information about the Python-list mailing list