# Tail Log
+ tail_ratelimiter = asyncio.Semaphore(1)
+
async def tail_log(self, limit):
"""
Tails the log file (i.e. returns the N last lines)
"""
- # Open the log file
- try:
- with await self.open_log() as f:
- return await asyncio.to_thread(collections.deque, f, limit)
+ async with self.tail_ratelimiter:
+ # Open the log file
+ try:
+ with await self.open_log() as f:
+ return await asyncio.to_thread(collections.deque, f, limit)
- # Return nothing if the log could not be opened
- except FileNotFoundError as e:
- return []
+ # Return nothing if the log could not be opened
+ except FileNotFoundError as e:
+ return []
# Import the logfile