summaryrefslogtreecommitdiffstats
path: root/tests/wqueue2.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/wqueue2.py')
-rwxr-xr-xtests/wqueue2.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/tests/wqueue2.py b/tests/wqueue2.py
index 0a3791f..635b52c 100755
--- a/tests/wqueue2.py
+++ b/tests/wqueue2.py
@@ -7,6 +7,7 @@ import asyncio
import os
import functools
import shutils
+import collections
u8open = functools.partial(open, encoding='utf8')
@@ -15,33 +16,35 @@ u8open = functools.partial(open, encoding='utf8')
class PersistentJobQueue2:
def __init__(self, filename, loop=None):
- self.queue = deque.deque()
- self.current_job = deque.deque()
+ self.queue = collections.deque()
+ self.current_job = collections.deque()
self.event = asyncio.Event(loop=loop)
self.loop = loop
def push_job(self, item):
- self.queue.push_right(item)
+ self.queue.append(item)
self.event.set()
async def get_job(self, item):
- if not self.current_job.empty():
+ if len(self.current_job):
return self.current_job[0]
- if not self.queue.empty():
+ if len(self.queue):
job_item = self.queue.pop()
else:
self.event.clear()
await self.event.wait()
job_item = self.queue.pop()
- self.current_job.push_right(self.queue.pop())
+ self.current_job.append(job_item))
return self.current_job[0]
async def mark_job_done(self):
- assert not self.current_job.empty()
+ assert len(self.current_job)
self.current_job.pop()
def dump_queue(self, filename):
'''
+ dump and clean the queue in order for it to be edited.
+
note: current file is not saved since it would be inconsistent if
the queue is reloaded but file has finished being processed
between.
@@ -57,6 +60,9 @@ class PersistentJobQueue2:
f.write(self.queue.dump())
def reload_from_filename(self, filename):
+ '''
+ reloads a queue after editing it.
+ '''
with u8open(filename) as f:
items = f.read().parse()