Asynchronous library to watch files in real time.
Project description
Library to “watch” files in a directory and call a callback function (file name, lines) every time one of the files being monitored is recorded, in real time.
Practically speaking, this can be compared to tail -F *.log UNIX command, but instead of having lines printed to stdout a python function gets called.
Similarly to tail, it takes care of “watching” new files which are created after initialization and “unwatching” those ones which are removed in the meantime. This means you’ll be able to “follow” and support also rotating log files.
Code examples
All code examples requires python 3.6+.
Basic Usage
import asyncio
from aiowatcher import AIOWatcher
async def callback(filename, line):
print(line)
async def main():
lw = AIOWatcher('var', callback, extensions=['txt'])
await lw.init()
await lw.loop()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Non blocking
import asyncio
from aiowatcher import AIOWatcher
async def callback(filename, line):
print(line)
async def main():
lw = AIOWatcher('var', callback, extensions=['txt'])
while True:
await lw.loop(blocking=False)
await asyncio.sleep(0.1)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aiowatcher-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e7bfcc2ff4dc4d0faa107340540ed9c2c6f0b569a3f1169ace50c5d38219a35 |
|
MD5 | 769d85ef9ead7704377284a121fdf42b |
|
BLAKE2b-256 | fec4427e53ddaad982a0b790d3b9c2fde4aaa32a0f5d1d01675c2bb0958e7760 |