shubham kumar
How to stop a long running thread?
By shubham kumar in Threading on Jul 16 2012
  • Munesh Sharma
    Oct, 2014 13

    Well from you question and subsequent comments I can suggest you two options, with some additional "warnings":If your thread loops executing something on each iteration, you can set a volatile boolean flag such that it exits after finishing the current iteration (pseudocode because I'm not familiar with python):while shouldExit = false// do stuff Then just set the flag to true when you want the thread to stop and it will stop the next time it checks the condition.If you cannot wait for the iteration to finish and need to stop it immediately, you could go for Thread.Abort, but make absolutely sure that there is no way you can leave open file handles, sockets, locks or anything else like this in an inconsistent state.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS