From 489012936025c9bc96b97b2e030e882e33a53b9d Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 15 Feb 2020 18:00:09 -0800 Subject: [PATCH] Add argument stop_event to safely finish & quit a copy thread. --- voussoirkit/spinal.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/voussoirkit/spinal.py b/voussoirkit/spinal.py index 5dd3160..0286d87 100644 --- a/voussoirkit/spinal.py +++ b/voussoirkit/spinal.py @@ -97,6 +97,7 @@ def copy_dir( files_per_second=None, overwrite_old=True, precalcsize=False, + stop_event=None, validate_hash=False, ): ''' @@ -186,6 +187,12 @@ def copy_dir( 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: Passed directly into each `copy_file`. @@ -234,6 +241,9 @@ def copy_dir( exclude_filenames=exclude_filenames, ) for source_file in walker: + if stop_event and stop_event.is_set(): + break + if source_file.is_link: continue