Issue with python schedule library
You are currently explicitly calling the getRegressionData
function with the argument subredditList
and pass the return value to do
.
As per the docs, do
accepts a function and optional positional and keyword arguments. It then calls the function for you at the desired time with the provided arguments.
Use do(getRegressionData, subredditList)
.
How to schedule a periodic task that is immune to system time change using Python
From the sched documentation:
class sched.scheduler(timefunc, delayfunc)
The scheduler class defines a generic interface to scheduling events. It needs two functions to actually deal with the “outside
world” — timefunc should be callable without arguments, and return a
number (the “time”, in any units whatsoever). The delayfunc function
should be callable with one argument, compatible with the output of
timefunc, and should delay that many time units. delayfunc will also
be called with the argument 0 after each event is run to allow other
threads an opportunity to run in multi-threaded applications.
The problem you have is that your code uses time.time()
as timefunc
, whose return value (when called without arguments) is the current system time and is thus affected by re-winding the system clock.
To make your code immune to system time changes you'd need to provide a timefunc
which doesn't depend on the system time, start/current timestamps, etc.
You can write your own function, for example one returning the number of seconds since your process is started, which you'd have to actually count in your code (i.e. don't compute it
based on timestamp deltas). The time.clock()
function might help, if it's based on CPU time counters, but I'm not sure if that's true or not.
Creating an internal clock within Coldfusion .cfc file to execute scheduled tasks
This can actually be done via Scheduled Tasks within Coldfusion Administrator. I didn't know that was a thing before actually making this post. My apologies.
Thank you,
Scheduling Python Script to run every hour accurately
Maybe this can help: Advanced Python Scheduler
Here's a small piece of code from their documentation:
from apscheduler.schedulers.blocking import BlockingScheduler
def some_job():
print "Decorated job"
scheduler = BlockingScheduler()
scheduler.add_job(some_job, 'interval', hours=1)
scheduler.start()
How to schedule a function to run every hour on Flask?
You can use BackgroundScheduler()
from APScheduler package (v3.5.3):
import time
import atexit
from apscheduler.schedulers.background import BackgroundScheduler
def print_date_time():
print(time.strftime("%A, %d. %B %Y %I:%M:%S %p"))
scheduler = BackgroundScheduler()
scheduler.add_job(func=print_date_time, trigger="interval", seconds=60)
scheduler.start()
# Shut down the scheduler when exiting the app
atexit.register(lambda: scheduler.shutdown())
Note that two of these schedulers will be launched when Flask is in debug mode. For more information, check out this question.
Related Topics
May Std::Vector Make Use of Small Buffer Optimization
Multi-Threading Benchmarking Issues
How to Have Swift, Objective-C, C and C++ Files in the Same Xcode Project
Does the C++ Volatile Keyword Introduce a Memory Fence
Catching Exceptions from a Constructor's Initializer List
Why Is My Log in the Std Namespace
Why Does Printf("%F",0); Give Undefined Behavior
How to Pre-Allocate Memory for a Std::String Object
Why Does Ostream_Iterator Not Work as Expected
C++: Safe to Use Longjmp and Setjmp
C++: Construction and Initialization Order Guarantees
Issue When Scheduling Tasks Using Clock() Function
Fixing Segmentation Faults in C++
Are There Any Better Methods to Do Permutation of String
The Copy Constructor and Assignment Operator