Python Forum
Problem with module time and leap seconds
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with module time and leap seconds
#1
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!')
Reply
#2
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.
Reply
#3
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.
Reply
#4
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:*********************************************************

Making the new Excel file took: 0.039621829986572266 seconds

*********************************************************

Sorry to have troubled you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with memory_graph module akbarza 3 377 Mar-04-2024, 10:15 AM
Last Post: snippsat
  problem using coloeama module akbarza 3 584 Jan-08-2024, 07:31 AM
Last Post: akbarza
Question Need Help with Vehicle Routing Problem with Time Windows (VRPTW) in Python kasper321421312 1 575 Nov-10-2023, 08:19 PM
Last Post: snippsat
  problem in using subprocess module akbarza 5 1,043 Sep-24-2023, 02:02 PM
Last Post: snippsat
  problem in import module from other folder akbarza 5 1,440 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  problem in using pyqrcode module to create QRcode akbarza 9 2,003 Aug-23-2023, 04:17 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 1,019 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  Module 'time' has no attribute 'clock' Sophie 4 3,132 Jan-25-2022, 08:05 PM
Last Post: Sophie
  Store variable data and display sum after 60 seconds the_dude 11 3,467 Dec-16-2021, 07:07 PM
Last Post: deanhystad
  Installing time module Led_Zeppelin 2 11,950 Aug-31-2021, 02:16 PM
Last Post: Led_Zeppelin

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020