Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running Thread object cause twice running #5307

Closed
SigmaStar opened this issue Oct 23, 2023 · 2 comments
Closed

running Thread object cause twice running #5307

SigmaStar opened this issue Oct 23, 2023 · 2 comments

Comments

@SigmaStar
Copy link

SigmaStar commented Oct 23, 2023

following code cause MyThread object running twice.

import threading
import time
from flask import Flask

class MyThread(threading.Thread):
    def __init__(self):
        super().__init__()
        self.event = threading.Event()

    def run(self):
        print("Hello")


app = Flask(__name__)
t1 = MyThread()
t1.start()
app.run(host='0.0.0.0', port = 19001, debug = True)

set debug as False can avoid this problem but why is that? Is that a feature?

@SigmaStar
Copy link
Author

my python version is 3.9.13 and Flask version is 1.1.2

@ThiefMaster
Copy link
Member

ThiefMaster commented Oct 23, 2023

This is because of the dev server's autoreloader which restarts the process (the original one monitors for changes, while the new one runs the actual app)

I'd also question why you need to run a background thread in a webapp process (and not use celery, cronjobs, etc. to offload long-running or periodic tasks) ;)

@ThiefMaster ThiefMaster closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants