I am sending an Ajax request from a page to a Django function on my website. In that function I need to start a thread, which will execute a shell command to dump a video stream. How should I build the system to be able to kill this same thread by sending a different Ajax request later? There will be multiple threads like that at one time.
Asked
Active
Viewed 169 times
0
-
any reason you're not using [celery](http://www.celeryproject.org/)? – Hedde van der Heide Mar 19 '15 at 08:20
-
haven't tried it. How can I use it to solve my problem? Are there any other ways? – Alexander Mar 19 '15 at 08:38
-
So I read something about it. It ether sends the current state as messages (which are not guaranteed to be delivered) or stores them in a DB. "Polling the database for new states is expensive, and so you should increase the polling intervals of operations such as result.get().". It feels like I can just store the "recording/stop recording" states in the DB myself while checking them in a thread all the time, which is just as expensive. Am I wrong here? – Alexander Mar 19 '15 at 12:25
-
1@Alexander take a look at [this answer](http://stackoverflow.com/a/325528/1463275). You can have a global dict open_threads = {} that key is thread_id and value is thread itself. then You can properly kill them later. also don't forget using mutex properly when accessing this global dictionary. – Mohammad ali baghershemirani Mar 19 '15 at 13:47
-
@Mohammad, thanks! Seems like it might work, gonna give it a try – Alexander Mar 20 '15 at 11:24