Thread processing
Anders J. Munch
andersjm at dancontrol.dk
Thu Mar 6 05:13:10 EST 2003
"Paul Moore" <gustav at morpheus.demon.co.uk> 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)
post_thread_ended_notification()
return wrapped_threadprocedure
Now instead of
thread.start_new_thread(spam,...)
use
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