Python Forum
Assistance with running a few lines of code at an EXACT time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assistance with running a few lines of code at an EXACT time
#3
Some machines/operating systems may not schedule your process every millisecond (especially under load). So anything you do in python is dependent on the OS running your program "quickly" enough. (time.time_ns() is preferred over time.time())

But what I'd probably do to get fairly accurate while not spinning on a CPU constantly is to sleep() until a few seconds prior to the time you want. Then calculate what the target time will be in epoch time and spin in a loop until it passes.
Reply


Messages In This Thread
RE: Assistance with running a few lines of code at an EXACT time - by bowlofred - Feb-22-2021, 06:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 720 Feb-14-2024, 02:57 PM
Last Post: snippsat
  writing and running code in vscode without saving it akbarza 1 435 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  the order of running code in a decorator function akbarza 2 569 Nov-10-2023, 08:09 AM
Last Post: akbarza
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 1,102 Aug-31-2023, 05:36 PM
Last Post: deanhystad
Question Running an action only if time condition is met alexbca 5 1,376 Oct-27-2022, 02:15 PM
Last Post: alexbca
  Code Assistance needed in saving the file MithunT 0 845 Oct-09-2022, 03:50 PM
Last Post: MithunT
  Regular Expression search to comment lines of code Gman2233 5 1,735 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  Code running many times nad not just one? korenron 4 1,407 Jul-24-2022, 08:12 AM
Last Post: korenron
  Error while running code on VSC maiya 4 3,859 Jul-01-2022, 02:51 PM
Last Post: maiya
  code running for more than an hour now, yet didn't get any result, what should I do? aiden 2 1,550 Apr-06-2022, 03:41 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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