tailf
tail -f functionality for your python code. Track file appends and
truncations.
Python3.6+ is supported.
Examples
pip install tailf==0.2.5
import tailf
import time
with tailf.Tail(filename) as tail:
while True:
for event in tail:
if isinstance(event, bytes):
print(event.decode("utf-8"), end='')
elif event is tailf.Truncated:
print("File was truncated")
else:
assert False, "unreachable" # currently. more events may be introduced later
time.sleep(0.01) # save CPU cycles
# this example requires python3.7
import asyncio
import tailf
async def main():
with tailf.Tail(filename) as tail:
while True:
event = await tail.wait_event()
if isinstance(event, bytes):
print(event.decode("utf-8"), end='')
elif event is tailf.Truncated:
print("File was truncated")
else:
assert False, "unreachable" # currently. more events may be introduced later
asyncio.run(main())
Limitations
-
Truncation detection is unreliable in general. It is primarily tracked by file size decrease, which sometimes can be unreliable. In cases when a file grows large and is truncated seldom, this is sufficient.
-
Asynchronous tracking is done at timer events (0.01 seconds currently). Inotify support could solve this issue on linux. Feel free to suggest other solutions.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tailf-0.3.2.tar.gz
(7.6 kB
view details)
File details
Details for the file tailf-0.3.2.tar.gz.
File metadata
- Download URL: tailf-0.3.2.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a44ad2663bb0125798dd8a3dcb0298449a1cc684e33383b4cd4c47fc7553963
|
|
| MD5 |
65fe4f802f59b0966dcd3810c16c6920
|
|
| BLAKE2b-256 |
22fb8cc8466e4de3b54cc9e9b9fafad63c6926c9350f569382572f93272847c9
|