1

Actually I have this code :

#!/usr/bin/env python3
import sys
import requests
import random
from multiprocessing.dummy import Pool
from pathlib import Path
requests.urllib3.disable_warnings()

print ('Give name of txt file on _listeNDD directory (without.txt)'),
file = str(input())

if Path('_listeNDD/'+file+'.txt').is_file():
    print ('--------------------------------------------------------')
    print ("Found")
    print ('--------------------------------------------------------')
    print ('Choose name for the output list (without .txt)'),
    nomRez = str(input())
    filename = '_listeNDD/'+file+'.txt'
    domains = [i.strip() for i in open(filename , mode='r').readlines()]
else:
    print ('--------------------------------------------------------')
    exit('No txt found with this name')


def check(domain):
    try:
        r = requests.get('https://'+domain+'/test', timeout=5, allow_redirects = False)
        if "[core]" in r.text:
            with open('_rez/'+nomRez+'.txt', "a+") as f:
                print('https://'+domain+'/test', file=f)
    except:pass

mp = Pool(100)
mp.map(check, domains)
mp.close()
mp.join()
exit('finished')

Screen of the root file


With this code, it open text file on directory "_listeNDD" and I write new text file on directory "_rez". Obviously it's super fast for ten elements but when it gets a bigger I would like a progress bar to know if I have time to make a coffee or not.

I had personally tried using the github tqdm but unfortunately it shows a progress bar for every job it does, while I only want one for everything...

Any idea? Thank you

EDIT : Using this post, I did not succeed with

if __name__ == '__main__':
   p = Pool(100)
   r = p.map(check, tqdm.tqdm(range(0, 30)))
   p.close()
   p.join()

I don't have a high enough python level to master this so I may have badly integrated this into my code. I also saw:

if __name__ == '__main__':
   r = process_map(check, range(0, 30), max_workers=2)
ThirdCity
  • 11
  • 2
  • Does this answer your question? [Multiprocessing : use tqdm to display a progress bar](https://stackoverflow.com/questions/41920124/multiprocessing-use-tqdm-to-display-a-progress-bar) – Alex Mar 23 '21 at 13:57
  • I tried but... doesn't work for me – ThirdCity Mar 23 '21 at 14:17
  • You should show what you have tried. – Alex Mar 23 '21 at 14:34
  • At mp = Pool(100) I change with : `if __name__ == '__main__': with Pool(100) as p: r = list(tqdm.tqdm(p.imap(mp.map(check, domains), range(30)), total=30)) mp.close() mp.join()` – ThirdCity Mar 23 '21 at 14:41
  • 1
    Would `mp.map(check, tqdm.tqdm(domains))` do the job? – dibery Mar 23 '21 at 14:42
  • 1
    You should *edit your question* and show why you have tried – Mark Tolonen Mar 23 '21 at 14:44
  • I will edit soon with what I've tried, python is not my strong points About @dibery , `mp.map(check, tqdm.tqdm(domains))` do nothing, The program is working correctly but nothing is showed – ThirdCity Mar 23 '21 at 14:52
  • OK. If you're editing the question, remember to post the code that can actually be tested and run by others. (Minimum working example.) – dibery Mar 23 '21 at 15:00
  • Thank you for you advise, it's edited, I hope it will be ok – ThirdCity Mar 23 '21 at 15:30
  • Didn't find obvious issues. I think you can try the very first `Pool` example (square a list) at python's [doc](https://docs.python.org/3/library/multiprocessing.html). Then add `tqdm` to `[1,2,3]` and see if it produces a progress bar. – dibery Mar 24 '21 at 08:06
  • No problem, thank you anyway for you help :) – ThirdCity Mar 24 '21 at 20:09

0 Answers0