File tree Expand file tree Collapse file tree 1 file changed +27
-8
lines changed Expand file tree Collapse file tree 1 file changed +27
-8
lines changed Original file line number Diff line number Diff line change 2525import random
2626import secrets
2727import io
28+ from concurrent .futures import ProcessPoolExecutor , TimeoutError as FuturesTimeoutError
2829
2930faulthandler .enable ()
3031
@@ -61,6 +62,28 @@ def statvfs(path):
6162 statvfs = os .statvfs
6263
6364
65+ def is_mount_then_statvfs (mount_point : str ) -> bool :
66+ try :
67+ ismounted : bool = ismount (mount_point )
68+ if not ismounted :
69+ return False
70+ # This forces initialization of FUSE
71+ statvfs (mount_point )
72+ return True
73+ except EnvironmentError :
74+ traceback .print_exc ()
75+ return False
76+
77+
78+ def is_mount_then_statvfs_with_timeout (mount_point : str , timeout : float = 1.0 ) -> bool :
79+ with ProcessPoolExecutor (max_workers = 1 ) as executor :
80+ future = executor .submit (is_mount_then_statvfs , mount_point )
81+ try :
82+ return future .result (timeout = timeout )
83+ except FuturesTimeoutError :
84+ return False
85+
86+
6487def securefs_mount (
6588 data_dir : str ,
6689 mount_point : str ,
@@ -97,14 +120,10 @@ def securefs_mount(
97120 )
98121 try :
99122 for _ in range (300 ):
100- try :
101- if ismount (mount_point ):
102- statvfs (mount_point )
103- if sys .platform == "darwin" :
104- time .sleep (0.01 )
105- return p
106- except EnvironmentError :
107- traceback .print_exc ()
123+ if is_mount_then_statvfs_with_timeout (mount_point , timeout = 10.0 ):
124+ if sys .platform == "darwin" :
125+ time .sleep (0.01 )
126+ return p
108127 time .sleep (0.005 )
109128 raise TimeoutError (f"Failed to mount { repr (mount_point )} after many attempts" )
110129 except :
You can’t perform that action at this time.
0 commit comments