def test_parallel(num_threads=2, kwargs_list=None):
 assert (num_threads > 0)
 has_kwargs_list = (kwargs_list is not None)
 if has_kwargs_list:
  assert (len(kwargs_list) == num_threads)
 import threading
 def wrapper(func):
  @wraps(func)
  def inner(*args, **kwargs):
   if has_kwargs_list:
    update_kwargs = (lambda i: dict(kwargs, **kwargs_list[i]))
   else:
    update_kwargs = (lambda i: kwargs)
   threads = []
   for i in range(num_threads):
    updated_kwargs = update_kwargs(i)
    thread = threading.Thread(target=func, args=args, kwargs=updated_kwargs)
    threads.append(thread)
   for thread in threads:
    thread.start()
   for thread in threads:
    thread.join()
  return inner
 return wrapper

def test_parallel ( num_threads = 2 , kwargs_list = None ) : assert ( num_threads > 0 ) has_kwargs_list = ( kwargs_list is not None ) if has_kwargs_list : assert ( len ( kwargs_list ) == num_threads ) import threading def wrapper ( func ) : @ wraps ( func ) def inner ( * args , ** kwargs ) : if has_kwargs_list : update_kwargs = ( lambda i : dict ( kwargs , ** kwargs_list [ i ] ) ) else : update_kwargs = ( lambda i : kwargs ) threads = [ ] for i in range ( num_threads ) : updated_kwargs = update_kwargs ( i ) thread = threading . Thread ( target = func , args = args , kwargs = updated_kwargs ) threads . append ( thread ) for thread in threads : thread . start ( ) for thread in threads : thread . join ( ) return inner return wrapper
decorator to run the same function multiple times in parallel .