python - How to use file as a Queue -
i need use file queue don't know how start (also other aproach welcome), because have non-secure transmission between device , computer, , need data saved until sent , recieved. data list holds same type , amount of elements. imagine file structure:
file data 0 <- send_pointer data 1 data 2 data 3 <- new_item
so code like:
while true: data = data_gather() file.write(data, new_item) new_item += 1 x = file.read(send_pointer) if send_function(x): file.delete(send_pointer) send_pointer += 1 else: print('error sending x')
i hope understand issue, english not best.
edit installed module: https://pypi.python.org/pypi/pqueue/0.1.1
but don't know how use well. can't find way delete data have read file.
thanks!
edit 2 solved pqueue.
#!/usr/bin/python import time offset = 0 while true: infile=open("./log.txt") infile.seek(offset) line in infile: print line // offset=infile.tell() infile.close() time.sleep(10)
only updates log.txt printed using method