Skip to content

Forum in maintenance, we will back soon 🙂

A cautionary tale a...
 
Notifications
Clear all

A cautionary tale about using Flask in debug mode with Python Threads

4 Posts
3 Users
2 Reactions
263 Views
SSAdvisor
(@ssadvisor)
Posts: 1127
Noble Member
Topic starter
 

Let me just say I did hours of "debugging" just to find that if you use Flask in debug mode and are using Python Threads, the threads execute at least twice and sometimes 3 times.

I was creating a queue for email being sent to allow for one process to be sending the email and I was usually getting 2 but sometimes 1 and sometimes 3. I finally found the correct research query to determine that the issue was FLASK_DEBUG=true isn't compatible with running threads in an asynchronous manner. It didn't matter what I did to try to avoid the problem, there was always the potential for multiple emails.

Just wanted to share here so you can avoid wasted hours on trying to "debug" a problem in the code.

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 12/27/2023 8:12 pm
(@husein)
Posts: 409
Member Moderator
 

@ssadvisor thanks for the heads up!

 
Posted : 12/28/2023 9:17 am
Hasan Aboul Hasan
(@admin)
Posts: 1185
Member Admin
 

Thanks for sharing, but did you find out why?

Why would the debug mode fire threads this way? How, then, are we supposed to debug a multi-threaded app?

 
Posted : 12/28/2023 9:26 am
SSAdvisor
(@ssadvisor)
Posts: 1127
Noble Member
Topic starter
 

@admin not really other than some comment about debug mode starting 2 processes for some reason. It said something about needing that to monitor the changes in code.🤷

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 12/28/2023 7:25 pm
solarnebula reacted
Share:
[the_ad_group id=”312″]