Error in logging data to excel using Python

Hi guys,
I’m a new member here.

I’ve written code in Python to log data from a PLC to excel every second using time.sleep() function. As seen from the code below it should log data every second but when left overnight it skips logging data randomly for a duration ranging sometimes between 2 - 5 seconds.

I set the computer to never sleep as well so that cause is eliminated. Can someone have a look at my code below and advise. A copy of the code is as follows:

import sys
import os.path
import platform
import threading
import datetime
import pylogix
import time
import xlwt
import datetime
import openpyxl
import collections

from pylogix import PLC
from openpyxl import Workbook
from datetime import date

tags = [‘_IO_EM_DI_04’,‘_IO_EM_DI_05’]

with PLC() as comm:
comm.IPAddress = ‘XXX.XXX.X.XX’
comm.Micro800 = True
log_path = ‘C:/Documents/Log.xlsx’
workbook = openpyxl.load_workbook(log_path)

except FileNotFoundError:
workbook = openpyxl.Workbook()

sheet_name = ‘Log_’ +“%d-%m-%y”)
if sheet_name not in workbook.sheetnames:

sheet = workbook[sheet_name]
cell = sheet.cell(row =1, column = 1, value = ‘No.’)
cell = sheet.cell(row =1, column = 2, value = ‘Date’)
cell = sheet.cell(row =1, column = 3, value = ‘Time’)
cell = sheet.cell(row =1, column = 4, value = ‘Signal1’)
cell = sheet.cell(row =1, column = 5, value = ‘Signal2’)
log_counter = 1

while True:
Date =“%d-%m-%y”)
Time =
ret = comm.Read(‘_IO_EM_DI_05’)
ret1 = comm.Read(‘_IO_EM_DI_04’)
sheet.append([f’{log_counter}', Date, Time, ret.Value, ret1.Value])
log_counter += 1

except KeyboardInterrupt:
print(“Logging process interrupted.”)