Issue
Inside of each loop the thread is printing two times. In this case, it prints two times to each 3 seconds. I want that it prints only one time.
on Flask:
from flask import Flask
import threading
from time import sleep
app = Flask(__name__)
@app.route('/')
def index():
return 'ok'
def func():
count = 1
while True:
print(count)
count += 1
sleep(3)
t = threading.Thread(target=func)
t.setDaemon(True)
t.start()
if __name__ == '__main__':
app.run(debug=True)
output:
1
1
2
2
3
3
...
expected output:
1
2
3
...
Solution
I figured out the why.
When run modules like threading and apscheduler in Flask with debug mode: on ... it happens.
Answered By - rjunior8