The pre-requisite for understanding this blog post would be the following post. Please go through the following to set the context to understand what is discussed in this post.
Problem :
The flask app was running and was responding to a bunch of curl commands. This was single process thread that was working.
When the watchdog api was integrated and initiated with the flask program, the problem was that the watchdog thread was started and the flask app was never started. It was started only when the watchdog thread ended.
Since we want both the threads to be running, the watchdog process has to run in the background and the flask app to should run normally so that both functionalities are available for use.
Python thread and threading are the options available.
The "thread" starts a thread and waits for it to complete before proceeding with the rest of the flow to get executed.(But this is not what we want, right!!)
Threading starts a thread and runs in the background, the user won't know when the thread is ending but can track what is the status of the thread by using an isAlive check for the thread.
Thread:
Threading:
Important Note:
Please ensure that you are starting the thread and not waiting for it by any means.
Also, enable the daemonize option so that the background thread is closed when the main thread is stopped.
Also, enable the daemonize option so that the background thread is closed when the main thread is stopped.
Comments
Post a Comment