dosubot[bot] commented on issue #29831: URL: https://github.com/apache/superset/issues/29831#issuecomment-2263763924
<!-- Greeting --> Hey there, @philipuvarov! I'm here to help you out with any issues you're facing. I can assist with bug fixes, answer any questions you have, and guide you on becoming a contributor. Let's work together to resolve any issues you're experiencing while we wait for a human maintainer. <!-- Answer --> Creating a thread in `superset_config.py` causes the entire Superset app to freeze until the thread completes because the configuration file is executed in the main thread during the initialization of the application. This means that any blocking operation, such as creating and running a thread, will block the main thread and prevent the application from continuing its initialization process. To prevent this behavior, you should avoid running blocking operations directly in the configuration file. Instead, you can defer the execution of such operations to a later point in the application's lifecycle, such as after the application has fully initialized. Here is an example of how you can defer the execution of a blocking operation using a Flask application context: ```python # superset_config.py from threading import Thread from flask import current_app def my_background_task(): # Your long-running task here pass def start_background_task(): thread = Thread(target=my_background_task) thread.start() def init_app(app): with app.app_context(): start_background_task() # Add the init_app function to the list of functions to be called when the app is initialized APP_INITIALIZATION = [init_app] ``` In this example, the `init_app` function is added to the `APP_INITIALIZATION` list, which ensures that it will be called after the application has been initialized. The `start_background_task` function creates and starts a new thread for the long-running task, preventing it from blocking the main thread during the application's initialization <sup>[[1]](https://github.com/apache/superset/blob/master/superset/config.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org