question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BackgroundScheduler in python is running two instances instead of 1

See original GitHub issue

0

I am using the background scheduler in python to run one job which does the anlaysis and then update the database . Below is the code for the same : So expected behavior is it will run one thread and wait for 15 seconds then run for the second instance. But this is running two instances together and then taking the break the of 59 second. Below is the output of the job I am running with timestamp

`scheduler.add_job(func=print_date_time, trigger=“interval”,seconds=59)

scheduler.start()

print(scheduler.get_jobs())` ``

`job started at 02:54:11

in the beginning tweetid : blank new tid is : 1090278987920740353 tid not in the database job finished

job started at 02:54:13 in the beginning tweetid : blank new tid is : 1090278987920740353 tid not in the database job finished

job started 02:55:10 in the beginning tweetid : blank new tid is : 1090278987920740353 tid not in the database job finished

job started 02:55:12 in the beginning tweetid : blank new tid is : 1090278987920740353 tid not in the database job finished `************************************************************************************************************************************* I am trying to implement this flask app of python. This is causing inserting the key in the database twice and I am getting the duplicate entry error.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
agronholmcommented, Nov 26, 2021

Are you sure you don’t have two workers running the app? There is a FAQ entry about running APScheduler in web apps. Have you read it?

0reactions
corenuts007commented, Oct 22, 2022

Thanks for helping out. I did read it, but kind of missed that.

What worked for me was switching debug from True to False in Flask, though you can switch off the reloader apparently:

if name == ‘main’: app.run(debug=False)

https://stackoverflow.com/questions/27149386/issue-when-running-schedule-with-flask?rq=1

Thank you very much for solution

Read more comments on GitHub >

github_iconTop Results From Across the Web

apscheduler in Flask executes twice - python - Stack Overflow
I am debugging some problems for two weeks and only few minutes ago I realised it was scheduler running twice! And Google directed...
Read more >
Frequently Asked Questions — APScheduler 3.9.1 ...
The two most common issues are: Running the scheduler inside a uWSGI worker process while threads have not been enabled (see the next...
Read more >
APScheduler Documentation - Read the Docs
You typically have only one scheduler running in your application. ... using ProcessPoolExecutor instead to make use of multiple CPU cores.
Read more >
apscheduler - Bountysource
I am using the background scheduler in python to run one job which does the ... But this is running two instances together...
Read more >
Trigger 'cron' do not working in apscheduler 3 while 'interval ...
I am trying apscheduler 3.5.1 in python 3.6.3, running from windows. The cron triggered jobs never wake up. They will wake up if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found