Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6245231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:28:05+00:00 2026-05-24T12:28:05+00:00

how to terminate the thread when some variable value set to true? import threading

  • 0

how to terminate the thread when some variable value set to true?

import threading
class test(threading.Thread):
     def __init__(self):
         self.stopThread = False
         self.start():
     def start(self):
         while not self.stopThread:
              callOtherFunction    //which takes alomst 30 sec to execute
     def stop(self):
         self.stopThread = True

now the problem is that if the start function is called and while loop started then it will check the stop condition on next iteration, when it completed its internal work, so if the call is made to callOtherFunction then it still waits 30 sec to exit.. i want to immediately terminate the thread when the variable is set. is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:28:06+00:00Added an answer on May 24, 2026 at 12:28 pm

    This question was answered here:

    Is there any way to kill a Thread in Python?

    The bottom line is that, if you can help it, you should avoid killing a thread this way. However, if you must, there are some tricks you can try.

    Also, to be thread-safe, you should make self.stopThread a threading.Event() and use set() and clear() to signal when the thread should be stopped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I derive from threading.Thread: from threading import Thread class Worker(Thread): def start(self): self.running
# file1.py class _Producer(self): def __init__(self): self.chunksize = 6220800 with open('/dev/zero') as f: self.thing
I have some doubts on executing the following : public class Test { delegate
I have a simple test run of some medium-complexity code that won't terminate, i.e.
I cannot get a way to terminate a thread that is hung in a
Is it possible to terminate a running thread without setting/checking any flags/semaphores/etc.?
is there some way to terminate all (Java) applications launched with Eclipse at once?
I try to inject the exception to thread using signals, but some times the
I have one 'main' thread that creates an array of objects of class SlowData
I call obackgroundworker.CancelAsync(); on a background worker currently doing some work in another thread

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.