Skip to content

Commit c1f07d6

Browse files
fix: support py27 with scandir pkg
1 parent 4e16d90 commit c1f07d6

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎requirements.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ pbr
88
tenacity
99
tqdm
1010
requests>2,<3
11+
scandir

‎taskqueue/file_queue_api.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
import uuid
1111
import time
1212

13+
try:
14+
from os import scandir
15+
except ImportError:
16+
from scandir import scandir
17+
1318
import tenacity
1419

1520
from .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

Comments
 (0)