Serving the Quantitative Finance Community

 
User avatar
tags
Topic Author
Posts: 3162
Joined: February 21st, 2010, 12:58 pm

on running code today at a specific time

June 23rd, 2021, 8:06 pm

Easy question. In pseudocode/from a conceptual/logics perspective what is an appropriate/elegant way to launch a function (python, C++, ...) at say 07:00am today (we don't care about timezone)?  I mean something like:
if time == 07:00am:
    foo()
doesn't seem quite OK.
An actual use case may be along: the script is launched and it waits for a specific time to start all the machinery that downloads data from a webpage updated at that specific time (minus a small time delta).. 
Thank you for your suggestions.
 
User avatar
bearish
Posts: 5188
Joined: February 3rd, 2011, 2:19 pm

Re: on running code today at a specific time

June 23rd, 2021, 9:37 pm

I’d probably use scheduled tasks (Windows) or cron (Linux). I don’t think you want to do it inside your code. But I’m not an expert.
 
User avatar
katastrofa
Posts: 7440
Joined: August 16th, 2007, 5:36 am
Location: Alpha Centauri

Re: on running code today at a specific time

June 23rd, 2021, 9:51 pm

 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: on running code today at a specific time

June 23rd, 2021, 10:22 pm

Python, the insatiable gas guzzler

https://pypi.org/project/pyJoules/
 
User avatar
tags
Topic Author
Posts: 3162
Joined: February 21st, 2010, 12:58 pm

Re: on running code today at a specific time

June 24th, 2021, 7:51 pm

thank you friends for your suggestions.
Bearish. OK. on Windows they have VisualCron.
kata i didn't know the schedule library.
Cuch. I don't quite get your answer.

Anyways I would really have been interested on learning from you guys what is appropriate for "when it is that time, call that function", in programming logics.
 
User avatar
katastrofa
Posts: 7440
Joined: August 16th, 2007, 5:36 am
Location: Alpha Centauri

Re: on running code today at a specific time

June 29th, 2021, 6:50 pm

Scheduling algorithm design is the whole branch of computer science, but you are asking how to simply "phrase" a very basic schedule in pseudocode language?
IF scheduling instant t:
   THEN launch nuclear strike
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: on running code today at a specific time

June 29th, 2021, 8:10 pm

On toy computers a nuclear strike with Python is whaahy. In the good old 1970s IBM days even humble programmers has a virtual machine with JCL

https://en.wikipedia.org/wiki/Job_Control_Language

I did an AI search and found this

https://pypi.org/project/jobcontrol/

Who knows?
 
User avatar
tags
Topic Author
Posts: 3162
Joined: February 21st, 2010, 12:58 pm

Re: on running code today at a specific time

July 31st, 2021, 10:10 pm

hello. thank you friends for your additional questions/comments/suggestions.
yes, kata it is exactly what i'm after.
 
User avatar
kc11415
Posts: 72
Joined: March 16th, 2003, 10:02 pm
Location: Indiana, USA

Re: on running code today at a specific time

November 6th, 2021, 2:28 pm

Perhaps too late to chime in, since answer probably found elsewhere.
However, just planting a "see also" in this thread.
Multiple prior responses on this thread are really talking about job control; which is not what the OP asked.
Depending on job control means incurring the process startup time, and your function will absolutely NOT be ready to fire at your requested time.
The correct and actual answer to the OP is to:
* spawn a child thread
* in that thread either:
     - call a sleep function
     - in other languages there may be some sort of setinterval function
* when that thread wakes up, it can either call the desired function directly or send a signal to a signal handler which invokes that function.

Whatever you do, in a workplace or other shared computing venue, please do not have a loop that spins and repeatedly checking:

   "are we there yet?"
   "are we there yet?"
   "are we there yet?"
Since that is a good way to get the SysAdmin running down the hall asking who the hell is thrashing the server?!?!?
(I learned that firsthand)
All standard disclaimers apply, and then some.
 
User avatar
tags
Topic Author
Posts: 3162
Joined: February 21st, 2010, 12:58 pm

Re: on running code today at a specific time

November 6th, 2021, 4:20 pm

thank you for your valuable comments @kc11415