0

I'm working at an unzipper application, and i want to use multiple processes to unzip a number of files from a directory, and i want to have a screen to know about every process and what is it unzipping I'm really new to python programming and I'm new to multiprocessing also

When I'm complining this script, I want to see the status of every process but instead the files just get unzipped and nothing is printed to the screen, until the script has finished unzipping and it ends. Can someone please explain why there is no print on the screen?

import os, zipfile
from multiprocessing import Process
from unicurses import*
import time
dir_name = 'E:\zips'
extension = ".zip"
processes = 3
os.chdir(dir_name)
def unzipper(item,files,poz,no_proc):
    if(item.endswith(extension)):
        move(no_proc*2,5)
        addstr(f"#{no_proc} -> working on {item}...\n")
        getch()
        file_name = os.path.abspath(item)
        zip_ref = zipfile.ZipFile(file_name)
        zip_ref.extractall(dir_name)
        zip_ref.close()
        move(no_proc*2,5)
        addstr(f"#{no_proc} finised processing {item}.\n")
        if(poz-processes>=0):
            item=files.pop(poz-processes)
            unzipper(item, files,poz-processes,no_proc)
    else:
        os.kill(os.getpid())
if __name__ == '__main__':
    stdscr=initscr()
    print(os.getpid())
    procs = []
    i=0
    list = os.listdir(dir_name)
    files=[]
    for i in range(0,len(list)):
        if(list[i].endswith(extension)):
            files.append(list[i])
    for no_proc in range(0,processes):
        move((no_proc+1)*2,5)
        addstr(f"#{no_proc} -> ")    
    for no_proc in range(0,processes):
        if(files!=[]):
            item=files.pop()
            proc = Process(target=unzipper, args=(item,files,len(files),no_proc+1))
            procs.append(proc)
            proc.start()

    for proc in procs:
        proc.join()
ciuz99best
  • 63
  • 1
  • 9
  • Hi and welcome to Stack Overflow, I can't see a question in your text. Being more specific would help you getting relevant answers. – Jacques Gaudin Mar 26 '19 at 13:16
  • Consider importing tqdm: https://pypi.org/project/tqdm/ – J_H Mar 26 '19 at 13:29
  • @J_H with tqdm can i make all the processes to print data on the same terminal? For example for every process to show the currently unzipping file, and after it's done, the process proceeds to the next file, can it change the name also in the terminal? – ciuz99best Mar 26 '19 at 13:37
  • Use `position`, cf https://stackoverflow.com/questions/45742888/tqdm-using-multiple-bars#answer-46398645 – J_H Mar 26 '19 at 13:45

0 Answers0