Add argument stop_event to safely finish & quit a copy thread.

master
Ethan Dalool 2020-02-15 18:00:09 -08:00
parent 64d0968040
commit 4890129360
1 changed files with 10 additions and 0 deletions

View File

@ -97,6 +97,7 @@ def copy_dir(
files_per_second=None, files_per_second=None,
overwrite_old=True, overwrite_old=True,
precalcsize=False, precalcsize=False,
stop_event=None,
validate_hash=False, validate_hash=False,
): ):
''' '''
@ -186,6 +187,12 @@ def copy_dir(
Default = False Default = False
stop_event:
If provided, a threading.Event object which when set indicates that we
should finish the current file and then stop the remainder of the copy.
Default = None
validate_hash: validate_hash:
Passed directly into each `copy_file`. Passed directly into each `copy_file`.
@ -234,6 +241,9 @@ def copy_dir(
exclude_filenames=exclude_filenames, exclude_filenames=exclude_filenames,
) )
for source_file in walker: for source_file in walker:
if stop_event and stop_event.is_set():
break
if source_file.is_link: if source_file.is_link:
continue continue