copytree with timeout in windows

A

Astan Chee

Hi,
I'm trying to modify the copytree function in shutil so that any file
being copied does not take more than 5 minutes (if it does, skip to the
next one). This is what I have so far:

import shutil
import signal, os

def handler(signum, frame):
print 'Signal handler called with signal', signum
raise IOError, "Couldn't open device!"

signal.signal(signal.SIGALRM, handler)

def copytree(src, dst):
names = os.listdir(src)
os.makedirs(dst)
signal.alarm(0)
for name in names:
if name in ignored_names:
continue
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
try:
if os.path.isdir(srcname):
copytree(srcname, dstname, symlinks, ignore)
else:
signal.alarm(300)
shutil.copy2(srcname, dstname)
except (IOError, os.error), why:
print str(why)
# catch the Error from the recursive copytree so that we can
# continue with other files
except Error, err:
print str(err.args[0])

source = "c:\\testwa\\"
destination = "d:\\testwa\\"

copytree(source,destination)

Then I re-read the documentation which said that signal.SIGALRM is
unix/linux only. How do I go about doing this in windows?
Thanks for any help.
Cheers
Astan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top