Problem with module time and leap seconds - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Problem with module time and leap seconds (/thread-38388.html) |
Problem with module time and leap seconds - Pedroski55 - Oct-07-2022 I have a little programme to get rows from a big Excel file. Depending on the number of rows to fetch, the execution time varies a little, but shouldn't be more than 2 seconds. Yesterday, the timer was working fine. This morning I updated all modules according to advice from the internet: Quote:pip freeze > requirements.txt You are supposed to change all the == for >= in requirements.txt then: Quote:pip install -r requirements.txt --upgrade Now, the timing is about 6 seconds too much. Even a rough check using the stopwatch on my phone shows less than 3 seconds. I read just now, "Different platforms handle leap seconds differently." Anyone else have this problem? Anyone know how to fix this please? I tried using the module time and using datetime # start a timer to see how long this takes start = datetime.datetime.now() print('start time is', start) savename = makeXL(sF, mytup, sheet, path2files) paintYellow(savename) formatCells(savename) end = datetime.datetime.now() print('end time is', end) execution_time = end - start print('\n*********************************************************\n') print(f'Making the new Excel file took: {execution_time} seconds') print('\n*********************************************************\n') print(f'data taken from {myfile} and saved in {savename} !') print('All done!') RE: Problem with module time and leap seconds - Larz60+ - Oct-07-2022 You might want to use this package: https://pypi.org/project/pip-upgrader/ ( I haven't tried this package, and don't love the idea, but...) Note that upgrading all packages at once might possibly create compatibility problems. This is not necessarily bad, as it will force you to bring code up to date. Well written code shouldn't have this problem at all. RE: Problem with module time and leap seconds - deanhystad - Oct-07-2022 Using pip requirements is not going to change datetime. To update datetime you install a newer python version. Write a test to see if datetime is the problem. from datetime import datetime from time import sleep for i in range(1, 11): start = datetime.now() sleep(i) end = datetime.now() print(i, end-start)datetime is an odd choice for measuring short periods of time. RE: Problem with module time and leap seconds - Pedroski55 - Oct-07-2022 Thanks for your replies. I think the problem was me. My brain works OK at 5am, but come lunchtime, it runs out of steam! @deanhystad I tried your code, it took just over 55 seconds according to my stopwatch, which is correct, I believe. Yesterday, I changed the part for getting number values, put in a while loop so you can only enter < or > or =. I didn't move the position of start = time() choices = ['>', '<', '='] choice = 'X' while not choice in choices: choice = input('Enter greater than > or less than < or equal to = ... ') print('You entered', choice) start = time()Now I am getting the correct time: Quote:********************************************************* Sorry to have troubled you! |