0

I have a function code which works like:

Get PIL image using URL -> Convert to array -> apply functions which return a tuple of 2 values -> return a dictonary of those values

I am trying to track the process when I use Multiprocessing. I found many links but they don't work for me. This is the current code which is supposed to work but it does not.

from multiprocessing import Pool
from tqdm import tqdm
import numpy as np
from PIL import Image
import requests
from io import BytesIO

def function(url):
    try:
        _id = url.split('/')[-2]
        response = requests.get(url)
        img = Image.open(BytesIO(response.content))
        return {_id:get_blurs(np.array(img))}
    
    except:
        return {_id:(np.nan,np.nan)}

p = Pool(8)

ids = []
lap = []
fft = []

for result in tqdm(p.map(func=function, iterable=urls), total=len(urls)):
    items = list(result.items())[0]
    ids.append(items[0])
    lap.append(items[1][0])
    fft.append(items[1][1])


p.close()
p.join()

It is not giving me any progress bar or anything else. When I used this function with very simple functions, it worked but is not working with my code.

Deshwal
  • 2,461
  • 2
  • 17
  • 57
  • Did you check this solution? [link](https://stackoverflow.com/a/59905309/16349299) [link](https://github.com/tqdm/tqdm/blob/master/examples/parallel_bars.py) – mohamadmansourx Jul 13 '21 at 09:28

0 Answers0