Dschoni Dschoni - 4 years ago 146
Python Question

Implement timeout in windows filecopy

I want to copy a list of files on windows using python. When doing that manually, I see timeouts in some files, therefore the copy process fails. I need a way to implement the timeout check in python.

So far I use the win32 API:

import win32file
files = {'source_a' : 'dest_a', 'source_b' : 'dest_b'}

for f in files.keys():
win32file.CopyFileW(f,files[f],0)


In some cases, the
CopyFileW
function doesn't return in "reasonable time", for the sake of this discussion, let's say 5 seconds. How can I wrap this function to be checked against a timer?

Answer Source

Instead of CopyFile, use CopyFileEx which provides an interface that supports cancellation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download