summaryrefslogtreecommitdiffstats
path: root/tests/wqueue2.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/wqueue2.py')
-rwxr-xr-xtests/wqueue2.py50
1 files changed, 7 insertions, 43 deletions
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():