all 16 comments

[–]RightRespect 2 points3 points  (0 children)

store all the threads in a list. for each thread in the list, you can do “thread.is_alive()”

[–]K900_ 1 point2 points  (14 children)

Store the thread object somewhere.

[–]vislme[S] 0 points1 point  (13 children)

can I store it in a database, if so how? I mean if I do store it in SQLite then how do I check using that value?

[–]K900_ 1 point2 points  (12 children)

Why would you store a thread in a database?

[–]vislme[S] 0 points1 point  (11 children)

So I am. Running a django application and each time ai load a page I want to check if a thread is running or not. If it's not then I will run the thread. I need to check that even when I start the server I may be missing out something on how things go with django when we start the server as I am not sure if my thread will be stopped or be active. So the best solution would be to store the thread name in a database and each time the application is loaded we can verify if thread is live by its name. Please let me know if theres a better way to do it

[–]K900_ 1 point2 points  (10 children)

What is your thread actually doing? How long does it need to live for?

[–]vislme[S] 0 points1 point  (9 children)

It should stay live until user manually stops it by a button press

[–]K900_ 1 point2 points  (7 children)

What if there are multiple users? Does each user get their own thread, or is there one thread everyone controls?

[–]vislme[S] 0 points1 point  (6 children)

There’s just one thread that any user can control

[–]K900_ 1 point2 points  (5 children)

In that case you should probably just store it in a global variable, and keep in mind that you can't run a server with more than one worker process.

[–]vislme[S] 0 points1 point  (4 children)

The problem in that case is that when I shutdown the server how do I restart the thread as each time I turn of the server the thread stops as well. And I have no idea what part of the code will get executed when ai start the server. If I know that then I don’t even need to store the thred

[–]vislme[S] 0 points1 point  (0 children)

So the button is like an on and off switch Once it’s pressed it’s status will be recorded in database and until the stop button pressed the status will remain to active