Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from concurrent.futures import ThreadPoolExecutor;
- import socket;
- import math;
- import os;
- # /home/a221251782/Monitoramento/
- LOGFILEPATH = 'simula-log.log';
- SERVERHOST = 'localhost';
- SERVERPORT = 8191;
- MAXWORKERS = 4;
- def sendlines(lnchunk):
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sc:
- SERVER = (SERVERHOST, SERVERPORT);
- sc.connect(SERVER);
- separator = '\n';
- sc.sendall(separator.join(lnchunk).encode());
- #with:
- #def:
- def monitorfile():
- lastsize = os.path.getsize(LOGFILEPATH);
- with open(LOGFILEPATH, 'r') as fh:
- fh.seek(0, os.SEEK_END);
- tpexec = ThreadPoolExecutor(max_workers=MAXWORKERS);
- while True:
- currsize = os.path.getsize(LOGFILEPATH);
- if currsize > lastsize:
- rlines = fh.readlines();
- chunksize = max(1, math.floor(len(rlines) / MAXWORKERS));
- for i in range(0, len(rlines), chunksize):
- tpexec.submit(sendlines, rlines[i:i+chunksize]);
- #for:
- lastsize = currsize;
- #if:
- #while:
- #with:
- #def:
- if __name__ == '__main__': monitorfile();
Advertisement
Add Comment
Please, Sign In to add comment