Terry Reedy wrote: > r0g wrote: > >> The trick to threads is to create a subclass of threading.Thread, define >> the 'run' function and call the 'start()' method. I find threading quite >> generally useful so I created this simple generic function for running >> things in threads... > > Great idea. Thanks for posting this. > >> def run_in_thread( func, func_args=[], callback=None, callback_args=[] ): >> import threading >> class MyThread ( threading.Thread ): >> def run ( self ): >> >> # Call function >> if function_args: >> result = function(*function_args) >> else: >> result = function() > > The check is not necessary. by design, f(*[]) == f()
Excellent, thanks Terry :) I knew it would be simpler than I thought! I've been writing a lot of PHP and AS3 recently and it's easy to forget how python often just works without needing the same level of hand holding, error checking & defensive coding as other languages! > Names do not match param names ;=) Oops yeah! Thought I'd refactor my painfully verbose variable names before posting in a 70 char wide medium but it looks like I missed one! *blush* Roger. -- http://mail.python.org/mailman/listinfo/python-list