Say I have a raw descriptor for numeric files, and I need to get the current position in the file based on this.
import os, psutil
lp = lib.open('/path/to/file')
p = psutil.Process(os.getpid())
fd = p.get_open_files()[0].fd
while True:
buf = lp.read()
if buf is None:
break
device.write(buf)
print tell(fd)
The following code libhas a compiled library that does not allow access to the file object. In a loop, I use a built-in method readthat returns processed data. Data and length are not related to file position, so I cannot mathematically calculate the offset.
I tried to use fdopenhow fd = fdopen(p.get_open_files()[0].fd), but print fd.tell()only returned the first position in the file, which was not updated in the loop.
Is there a way to get the current position in real time in a file based on a file descriptor?