0

I've written a Python Flask application that I would like to host as a website so that I can access it from multiple different devices.

When the application starts, I spawn a thread. The core issue is that I only want one thread for all of my users.

Heroku seems to spawn this thread once every time I open the page. (So if I open two tabs, two threads spawn.)

I've looked into Sessions, but that seems to just isolate users. (If I could count the number of active sessions, that would suffice because I could then not spawn the thread if the count is 1 or higher.)

I also thought I might be able to use a Lock to have the threads self-destruct if they can't acquire the one lock. But, after looking into it, I don't think this will work either, because I think that each new user will spawn a new lock as well to give to its own thread.

How do I structure my code such that only one thread spawns, no matter how many users are on my site?

Pro Q
  • 3,618
  • 3
  • 31
  • 74

0 Answers0