0

I'm trying to write a very simple script in python to use Robocopy to copy some files from one dir to another. The files are around 35 Gb, so it takes some time to complete. this is what i'm trying:

   def processing():
        p=subprocess.Popen(['robocopy', f'{orig_dir}','/W:1','/R:5', f'{dest_dir}', '/E','/LOG:log.txt'])
        while p.poll() is None:
            pass
        else:
            print('not none')

The function works, I get the files copied and it informs back when the process is finished, but during the running time the all app freezes...

I tried with

p=subprocess.Popen(['robocopy', f'{orig_dir}','/W:1','/R:5', f'{dest_dir}', '/E','/LOG:log.txt'],shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)

But it stills hangs. Is it because i'm using the pool to check if it is finished? Is there a better way(not too complicated)?

Edit : I already confirmed that checking poll is what makes the "freezing"

what is the best way to know when the Robocopy is finished?

  • ok , i suspected that.. is there a way to still use the gui interface while it is copying, but still get the info when its done? – Lcross Portugal Nov 28 '21 at 20:31
  • The best way to do this is to write the program to run [asynchronously](https://docs.python.org/3/library/asyncio.html) you can see a good example can be found [here](https://stackoverflow.com/questions/16071866/non-blocking-subprocess-call) – Matthew Barlowe Nov 28 '21 at 23:12

0 Answers0