Skip to content

Commit 143a4fb

Browse files
committed
try to fix windows error
1 parent 580ca24 commit 143a4fb

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tests/setup_data.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22
import shutil
3+
import time
4+
import platform
35

46
# from projects import get_records_from_datadir, fix_config_paths
57
from deepethogram import projects
@@ -26,7 +28,27 @@ def change_to_deepethogram_directory():
2628

2729

2830
def clean_test_data():
29-
if os.path.isdir(project_path):
31+
if not os.path.isdir(project_path):
32+
return
33+
34+
# On Windows, we need to handle file permission errors
35+
if platform.system() == 'Windows':
36+
max_retries = 3
37+
for i in range(max_retries):
38+
try:
39+
shutil.rmtree(project_path)
40+
break
41+
except PermissionError:
42+
if i < max_retries - 1:
43+
time.sleep(1) # Wait a bit for file handles to be released
44+
continue
45+
else:
46+
# If we still can't delete after retries, try to ignore errors
47+
try:
48+
shutil.rmtree(project_path, ignore_errors=True)
49+
except:
50+
pass # If we still can't delete, just continue
51+
else:
3052
shutil.rmtree(project_path)
3153

3254

0 commit comments

Comments
 (0)