summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVG <vg@devys.org>2016-04-06 22:30:26 +0200
committerVG <vg@devys.org>2016-04-06 22:30:26 +0200
commite28490f18420e4c466614268140a7f8dbaaf2c78 (patch)
treec7b5810824668e473b1e4111cd7d596df61db9a0
parent5d1b21751b056342771e69a545e842440060199d (diff)
downloadwqueue-e28490f18420e4c466614268140a7f8dbaaf2c78.tar.gz
wqueue-e28490f18420e4c466614268140a7f8dbaaf2c78.tar.bz2
wqueue-e28490f18420e4c466614268140a7f8dbaaf2c78.zip
Auto-commit on 807fe7afb37fe2cfcf15c9457d04f64fa11b7511
-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()