In my code, I have a function that has an integer as an input. This input affects heavily the running time of this function. This is the code line where I call the function, with the input value of 0.35.
frequent_itemsets = get_frequent_items(0.35)
The get_frequent_items function returns a DataFrame, and next in the code I using this DataFrame for other computations, so I need this method to return the DataFrame (here called frequent_itemsets) to be able to continue the code.
Knowing that the input value of the integer of the function (here 0.35 ) in the example, affects the running time heavily, (for example if it is 0.35 the functions takes 28 seconds to return , and if it is 0.3, the function will take 2 Hours to return).
I am thinking of limiting the input options values for the function to the options
var_support_options = [0.18, 0.2, 0.25, 0.3, 0.35]
Now, my questions is, is there a way to write the code in a way that it try the function using these input values (provided in var_support_options) list, starting from the lowest value to the biggest.
EXAMPLE OF DESIRED process:
iteration 1 : frequent_itemsets = get_frequent_items(0.18)
if this iteration takes more than 30 seconds, stop the iteration and try the next value in the input list (in the example
0.2
).else if this takes less than 30 seconds, return the
frequent_itemsets
dataframe and continue the code.
I want the function to be done in less than 30 seconds using the least input integer value and then return the result and continue to the next lines of code.
Should I do that using multithreading
, multiprocessing
or other ? And how the code should be.