From 37ba4be062c037616fc8a19057090d236422d9c0 Mon Sep 17 00:00:00 2001 From: VG Date: Wed, 6 Apr 2016 22:43:21 +0200 Subject: Auto-commit on 807fe7afb37fe2cfcf15c9457d04f64fa11b7511 --- tests/limitations.notes | 4 ++++ tests/wqueue2.py | 50 +++++++------------------------------------------ 2 files changed, 11 insertions(+), 43 deletions(-) create mode 100644 tests/limitations.notes diff --git a/tests/limitations.notes b/tests/limitations.notes new file mode 100644 index 0000000..d723c07 --- /dev/null +++ b/tests/limitations.notes @@ -0,0 +1,4 @@ +Queue is not saved between invocations of the queue. The queue is a living +queue only. It can be edited (for waiting items only), thus if you want to +save a queue, you can always copy the list and restore it with another edit, +but it is a hack. diff --git a/tests/wqueue2.py b/tests/wqueue2.py index 635b52c..087e345 100755 --- a/tests/wqueue2.py +++ b/tests/wqueue2.py @@ -57,54 +57,18 @@ class PersistentJobQueue2: wanted result is a success: do not close the queue. ''' with u8open(filename, 'w') as f: - f.write(self.queue.dump()) + for item in self.queue: + print(item, file=f) + self.queue.clear() def reload_from_filename(self, filename): ''' - reloads a queue after editing it. + reloads a queue after editing it externaly. ''' with u8open(filename) as f: - items = f.read().parse() - - -class PersistentJobQueue: - - def __init__(self, filename): - self.filename = filename - self.lock = asyncio.Lock() - - - def append(self, item): - async with lock: - self.queue.append(item) - with u8open(self.filename, 'a') as f: - await f.write(item) - await f.write('\n') - - async def get_job(self): - async with lock: - self.current_job.append(self.queue.pop()) - return self.current_job[0] - - async def mark_job_done(self): - async with lock: - self.current_job.pop() - - async def pop(self): - # TODO: when wanting to pop an empty queue the pop should wait - # asynchronously for a new filename to arrive - error - firstline = None - async with lock: - with u8open(filename, 'r') as f, \ - u8open(filename + '.tmp', 'w') as fo: - async for line in f: - if not firstline: - firstline = line - else: - await fo.write(line) - shutils.mv(filename + '.tmp', filename) - return firstline + for item in f: + self.queue.append(item) + self.event.set() async def test(): -- cgit v1.2.3