This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
from functools import wraps | |
def threadify(num_threads,is_method=True,outputs_list=False,outputs_bool = False,outputs_gen=False): | |
''' Apply this decorator to a function. It turns that function into a new one that splits its work up among threads. This only works on special functions though. The first argument must be a list. This list will be split into even pieces with each piece passed to a thread. Your function must return either None,a list, or a dictionary. If it is a list make sure you specify outputs list as true. Lists are not guaranteed to return in order so dicts are best in most cases. The return of each thread will automatically be combined for you. The overhead is quite low''' | |
def threadify_real(func): | |
def threaded(*args,**kwargs): | |
threads = [] |