My Five task are not working continously

144 views
Skip to first unread message

Abishek Rajagopal

unread,
Jul 16, 2020, 7:22:56 AM7/16/20
to APScheduler
Task i snippet:

""
""
"The Below Task should run every 5 minutes"
""
""

from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta


sched = BackgroundScheduler({'apscheduler.timezone': 'UTC',
                             'apscheduler.job_defaults.coalesce': 'false',
                             'apscheduler.job_defaults.max_instances': '1', })


def startProcess():


    
    sched.get_jobs()
    sched.remove_all_jobs()
    # schedule the method 'printing_something' to run the the given 'date_time' with the args 'text'
    job = sched.add_job(process, 'interval', minutes=5, replace_existing=True, max_instances=1)
    sched.start()


Task ii snippet:

""
""
"The Below Task should run every Hour @ minute 10 eg. 1:10,2:10,3:10,...,23:10 everyday"
""
""

from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta


sched = BackgroundScheduler({'apscheduler.timezone': 'UTC',
                             'apscheduler.job_defaults.coalesce': 'false',
                             'apscheduler.job_defaults.max_instances': '1', })


def startProcess():


    
    sched.get_jobs()
    sched.remove_all_jobs()
    # schedule the method 'printing_something' to run the the given 'date_time' with the args 'text'
    job = sched.add_job(startaggregating, 'cron', minute=10,replace_existing=True,max_instances= 1)
    sched.start()


Task iii snippet:

""
""
"The Below Task should run every day @ hour 2AM".
""
""

from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta


sched = BackgroundScheduler({'apscheduler.timezone': 'UTC',
                             'apscheduler.job_defaults.coalesce': 'false',
                             'apscheduler.job_defaults.max_instances': '1', })

def startProcess():


    
    sched.get_jobs()
    sched.remove_all_jobs()
    # schedule the method 'printing_something' to run the the given 'date_time' with the args 'text'
    job = sched.add_job(startaggregating, 'cron', hour=2, replace_existing=True, max_instances=1)
    sched.start()


Task iv and v similar to i:


Hello Team,


         I have implemented apscheduler in my python django project. i ran this my sever . but after someday some of these task stops unwanted without any error. but one such time i got "Schdulor Already running". please help by solving this issue. 
Am i getting this issue because "max_instances=1"?
Am i getting this issue because "replace_existing=True"?
or the task is unwantedly stopping for other reasons?

thanks a lot in advance



Alex Grönholm

unread,
Jul 16, 2020, 7:56:15 AM7/16/20
to apsch...@googlegroups.com

From these snippets, it's not possible to get the "scheduler already running" error, so I must conclude that you are showing something else here than what you're actually running. Could you construct a minimum viable example that we can run so it would be possible to analyze the problem you're having?

--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/efbf7032-e144-4c1a-95d4-4c488ca7a5e1o%40googlegroups.com.

Abishek Rajagopal

unread,
Jul 20, 2020, 8:26:08 AM7/20/20
to APScheduler
oki, i just explained how every task schedulors calls function which is encode in it. All tasks are written in different files and called seperately.

if i start task i @ 5:50 pm 20-Jul-2020
it will run @5.55 20-Jul-2020  ,6:00pm 20-Jul-2020  ,6:05pm 20-Jul-2020....etc

if i start task ii @ 5:50 pm 
it will run @6:10pm 20-Jul-2020  ,7:10pm  20-Jul-2020   ,8:10pm 20-Jul-2020  ....etc


if i start task iii @ 5:50 pm 20-Jul-2020
it will run @2:00am 21-Jul-2020, 2:00am 22-Jul-2020,  2:00am 23-Jul-2020 ...etc


Task i snippet:

""
""
"The Below Task should run every 5 minutes"
""
""
from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta


sched = BackgroundScheduler({'apscheduler.timezone': 'UTC',
                             'apscheduler.job_defaults.coalesce': 'false',
                             'apscheduler.job_defaults.max_instances': '1', })


def startProcess():


    
    sched.get_jobs()
    sched.remove_all_jobs()
    # schedule the method 'printing_something' to run the the given 'date_time' with the args 'text'
    job = sched.add_job(process, 'interval', minutes=5, replace_existing=True, max_instances=1)
    sched.start()

def process():
    print("every 5 minutes")

Task ii snippet:

""
""
"The Below Task should run every Hour @ minute 10 eg. 1:10,2:10,3:10,...,23:10 everyday"
""
""

from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta


sched = BackgroundScheduler({'apscheduler.timezone': 'UTC',
                             'apscheduler.job_defaults.coalesce': 'false',
                             'apscheduler.job_defaults.max_instances': '1', })


def startProcess():


    
    sched.get_jobs()
    sched.remove_all_jobs()
    # schedule the method 'printing_something' to run the the given 'date_time' with the args 'text'
    job = sched.add_job(startaggregating, 'cron', minute=10,replace_existing=True,max_instances= 1)
    sched.start()

def startaggregating():
    print("every hour")


Task iii snippet:

""
""
"The Below Task should run every day @ hour 2AM".
""
""

from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta


sched = BackgroundScheduler({'apscheduler.timezone': 'UTC',
                             'apscheduler.job_defaults.coalesce': 'false',
                             'apscheduler.job_defaults.max_instances': '1', })

def startProcess():


    
    sched.get_jobs()
    sched.remove_all_jobs()
    # schedule the method 'printing_something' to run the the given 'date_time' with the args 'text'
    job = sched.add_job(startaggregating, 'cron', hour=2, replace_existing=True, max_instances=1)
    sched.start()

def startaggregating():
    print("Every day")

Task iv and v similar to i:

To unsubscribe from this group and stop receiving emails from it, send an email to apsch...@googlegroups.com.

Alex Grönholm

unread,
Jul 20, 2020, 8:28:44 AM7/20/20
to apsch...@googlegroups.com

Do you need all this for a "minimum viable" example? Your problem absolutely cannot be reproduced without trying to run all five tasks?

Also, none of the snippets even start the scheduler, so how is this supposed to reproduce the problem?

To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/e2d68540-5caa-44d2-b4ca-16ca0f8816f8o%40googlegroups.com.

Abishek Rajagopal

unread,
Jul 20, 2020, 8:33:39 AM7/20/20
to APScheduler
I think this might work now
normally all snippet are in separate file and startprocess() function in each snippet will be called from a seperate program outside. I think now this will work.

Task i snippet:

""
""
"The Below Task should run every 5 minutes"
""
""
from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta


sched = BackgroundScheduler({'apscheduler.timezone': 'UTC',
                             'apscheduler.job_defaults.coalesce': 'false',
                             'apscheduler.job_defaults.max_instances': '1', })


def startProcess():


    
    sched.get_jobs()
    sched.remove_all_jobs()
    # schedule the method 'printing_something' to run the the given 'date_time' with the args 'text'
    job = sched.add_job(process, 'interval', minutes=5, replace_existing=True, max_instances=1)
    sched.start()

def process():
    print("every 5 minutes")

startProcess()

Task ii snippet:

""
""
"The Below Task should run every Hour @ minute 10 eg. 1:10,2:10,3:10,...,23:10 everyday"
""
""

from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta


sched = BackgroundScheduler({'apscheduler.timezone': 'UTC',
                             'apscheduler.job_defaults.coalesce': 'false',
                             'apscheduler.job_defaults.max_instances': '1', })


def startProcess():


    
    sched.get_jobs()
    sched.remove_all_jobs()
    # schedule the method 'printing_something' to run the the given 'date_time' with the args 'text'
    job = sched.add_job(startaggregating, 'cron', minute=10,replace_existing=True,max_instances= 1)
    sched.start()

def startaggregating():
    print("every hour")

startProcess()


Task iii snippet:

""
""
"The Below Task should run every day @ hour 2AM".
""
""

from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta


sched = BackgroundScheduler({'apscheduler.timezone': 'UTC',
                             'apscheduler.job_defaults.coalesce': 'false',
                             'apscheduler.job_defaults.max_instances': '1', })

def startProcess():


    
    sched.get_jobs()
    sched.remove_all_jobs()
    # schedule the method 'printing_something' to run the the given 'date_time' with the args 'text'
    job = sched.add_job(startaggregating, 'cron', hour=2, replace_existing=True, max_instances=1)
    sched.start()

def startaggregating():
    print("Every day")
startProcess()

Task iv and v similar to i:

Alex Grönholm

unread,
Jul 20, 2020, 8:36:25 AM7/20/20
to apsch...@googlegroups.com

Are you able to reproduce the problem by running task I snippet then? Note that the application exits immediately when it reaches the end of the script since you are starting a background scheduler and there is nothing preventing the main thread from exiting.

To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/718a0052-946b-49d8-93ab-d767e0df2e59o%40googlegroups.com.

Abishek Rajagopal

unread,
Jul 20, 2020, 8:38:17 AM7/20/20
to APScheduler
there no problem when Im starting all these task. but after one or two day these task stop unwanted with out any error and return statement.

Alex Grönholm

unread,
Jul 20, 2020, 8:40:49 AM7/20/20
to apsch...@googlegroups.com

You have to understand that I do not have whatever mechanism you have there that runs these scripts, so there is no way for me to reproduce the same setting as you have. That's why I'm asking you to minimize these examples so that I can also see the problem as it happens.

For what it's worth, the error you're getting indicates that your code is trying to start the scheduler twice so it's not really a problem with APScheduler.

To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/d9592ccb-6c1d-49c5-8a0f-dfe46b0a46bdo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages