The fitting procedure in the ROOT is extremely slow, so, if one want to perform many different fits on hundreds of histograms it is better to do it somehow in parallel.

So, there is a function to handle the histogram fits:

```
def apply_fit(hist, fit, *frange):
hist.Fit(fit, "0Q", "", *frange)
return fit
```

With the ThreadPool you can use it like this:

```
pool = ThreadPool(4)
list1 = (hist1, fit_thermal, *fit_range)
list2 = (hist1, fit_doubleexponent, *fit_range)
list3 = (hist1, fit_blastwave, *fit_range)
list4 = (hist1, fit_boseeinstein, *fit_range)
result = pool.starmap(apply_fit, [list1, list2, list3, list4])
```

And it will work and within `results`

youâ€™ll get your fits.

But ThreadPool is slow due to the GIL in the Python, so for the CPU tasks one must use the `multiprocessing.Pool`

, e.g.:

```
pool = multiprocessing.Pool(processes=4)
list1 = (hist1, fit_thermal, *fit_range)
list2 = (hist1, fit_doubleexponent, *fit_range)
list3 = (hist1, fit_blastwave, *fit_range)
list4 = (hist1, fit_boseeinstein, *fit_range)
result = pool.starmap(apply_fit, [list1, list2, list3, list4])
```

Both `hist`

and `fit`

objects (TH1D, TF1) are passed well to the function with the needed parameters for the each fit, but the fit function in the case returns `Invalid FitResult (status = 2 )`

â€“ it always stops after the second iteration.

So, the question is, how to deal with fits and multiprocessing?

*ROOT Version:* 6.32.00

*Platform:* Linux, MacOS

*Compiler:* gcc, llvm