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
#1
I'm not sure if this is the correct area, so I apologize, anyways, I'm new to learning python, for the past 2 days I've been looking for an answer to this. I want to add code that can make it so it pauses the script (not ending it) and then at an exact time it will run the few lines below it. Such as if I wanted it to pause it until 10:40 pm, I need it to be accurate to the very millisecond. Example: 2021 2 21 22 40 00 00 Year month day hour minute(s) second(s) millisecond(s)

The closest code to it that I got didn't do it accurately and most of the time had a second or more delay.
---The code
import sched
import time as time_module
def myfunc(): print("test123")

scheduler = sched.scheduler(time_module.time, time_module.sleep)
t = time_module.strptime('2021-02-21 22:25:14', '%Y-%m-%d %H:%M:%S')
t = time_module.mktime(t)
scheduler_e = scheduler.enterabs(t, 1, myfunc, ())
scheduler.run()
---
I put the rest of my code here.
Reply


Messages In This Thread
Assistance with running a few lines of code at an EXACT time - by nethatar - Feb-22-2021, 04:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 666 Feb-14-2024, 02:57 PM
Last Post: snippsat
  writing and running code in vscode without saving it akbarza 1 397 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  the order of running code in a decorator function akbarza 2 536 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,057 Aug-31-2023, 05:36 PM
Last Post: deanhystad
Question Running an action only if time condition is met alexbca 5 1,321 Oct-27-2022, 02:15 PM
Last Post: alexbca
  Code Assistance needed in saving the file MithunT 0 821 Oct-09-2022, 03:50 PM
Last Post: MithunT
  Regular Expression search to comment lines of code Gman2233 5 1,700 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  Code running many times nad not just one? korenron 4 1,377 Jul-24-2022, 08:12 AM
Last Post: korenron
  Error while running code on VSC maiya 4 3,776 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,515 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