1010import uuid
1111import time
1212
13+ try :
14+ from os import scandir
15+ except ImportError :
16+ from scandir import scandir
17+
1318import tenacity
1419
1520from .registered_task import totask , totaskid
@@ -272,7 +277,7 @@ def cancel_lease(self, task):
272277 def release_all (self ):
273278 """Voids all leases and sets all tasks to available."""
274279 now = nowfn ()
275- for file in os . scandir (self .queue_path ):
280+ for file in scandir (self .queue_path ):
276281 if get_timestamp (file .name ) < now :
277282 continue
278283
@@ -319,7 +324,7 @@ def fmt(direntry):
319324 return (int (timestamp ), filename )
320325
321326 now = nowfn ()
322- files = ( fmt (direntry ) for direntry in os . scandir (self .queue_path ) )
327+ files = ( fmt (direntry ) for direntry in scandir (self .queue_path ) )
323328
324329 leasable_files = []
325330
@@ -384,8 +389,8 @@ def tally(self):
384389
385390 def purge (self ):
386391 all_files = itertools .chain (
387- os . scandir (self .queue_path ),
388- os . scandir (self .movement_path )
392+ scandir (self .queue_path ),
393+ scandir (self .movement_path )
389394 )
390395 for file in all_files :
391396 try :
@@ -405,10 +410,10 @@ def read(path):
405410 with open (path , 'rt' ) as f :
406411 return f .read ()
407412
408- return ( read (f .path ) for f in os . scandir (self .queue_path ) )
413+ return ( read (f .path ) for f in scandir (self .queue_path ) )
409414
410415 def __len__ (self ):
411- return functools .reduce (operator .add , ( 1 for f in os . scandir (self .queue_path ) ), 0 )
416+ return functools .reduce (operator .add , ( 1 for f in scandir (self .queue_path ) ), 0 )
412417
413418
414419
0 commit comments