Python Forum
function call at defined system time?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function call at defined system time?
#6
There are also libraries that work fine for like schedule, APScheduler, pycron
The two first have i used serval times before,Python job scheduling for humans is maybe the easiest to use.

Holon Wrote:I would like to use asyncio for that
That's maybe overkill for this task,as usually don't need 1000's task to load at same time for this.
Schedule use simpler Threading if that's needed.
import threading
import time
import schedule


def job():
    print(f"I'm running on thread {threading.current_thread()}")

def run_threaded(job_func):
    job_thread = threading.Thread(target=job_func)
    job_thread.start()

schedule.every(10).seconds.do(run_threaded, job)
schedule.every(10).seconds.do(run_threaded, job)
schedule.every(10).seconds.do(run_threaded, job)

while 1:
    schedule.run_pending()
    time.sleep(1)
APScheduler start separate Thread automatic with schedulers.background
apscheduler Wrote:A scheduler that runs in the background using a separate thread (start() will return immediately).
Reply


Messages In This Thread
function call at defined system time? - by Holon - Oct-06-2020, 08:10 AM
RE: function call at defined system time? - by snippsat - Oct-06-2020, 03:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 588 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,303 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  return next item each time a function is executed User3000 19 2,286 Aug-06-2023, 02:29 PM
Last Post: deanhystad
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 796 May-02-2023, 08:40 AM
Last Post: Gribouillis
  Getting NameError for a function that is defined JonWayn 2 1,109 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,896 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  How to print the output of a defined function bshoushtarian 4 1,313 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  User-defined function to reset variables? Mark17 3 1,653 May-25-2022, 07:22 PM
Last Post: Gribouillis
  Mock obj - How to call the side_effect every time during the run? pythonisbae 3 2,639 Mar-06-2022, 09:37 AM
Last Post: pythonisbae
  time function does not work tester_V 4 3,042 Oct-17-2021, 05:48 PM
Last Post: tester_V

Forum Jump:

User Panel Messages

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