diff options
author | VG <vg@devys.org> | 2016-04-06 22:43:21 +0200 |
---|---|---|
committer | VG <vg@devys.org> | 2016-04-06 22:43:21 +0200 |
commit | 37ba4be062c037616fc8a19057090d236422d9c0 (patch) | |
tree | 2adbfcba0c2a3d257bdbba2886a909bd4cd6c075 | |
parent | e28490f18420e4c466614268140a7f8dbaaf2c78 (diff) | |
download | wqueue-37ba4be062c037616fc8a19057090d236422d9c0.tar.gz wqueue-37ba4be062c037616fc8a19057090d236422d9c0.tar.bz2 wqueue-37ba4be062c037616fc8a19057090d236422d9c0.zip |
Auto-commit on 807fe7afb37fe2cfcf15c9457d04f64fa11b7511
-rw-r--r-- | tests/limitations.notes | 4 | ||||
-rwxr-xr-x | tests/wqueue2.py | 50 |
2 files changed, 11 insertions, 43 deletions
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(): |