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

  • SEARCH
  • Home
  • 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 8604165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:30:16+00:00 2026-06-12T02:30:16+00:00

Suppose inside run() method of a python Thread , I check a flag.If that

  • 0

Suppose inside run() method of a python Thread , I check a flag.If that flag is True , I assume my thread should exit has done it’s job and should exit.

How should I exit the thread at that point ? Trying Thread.exit()

class  workingThread(Thread):

    def __init__(self, flag):
        Thread.__init__(self)
        self.myName = Thread.getName(self)
        self.FLAG= flag
        self.start()    # start the thread

    def run(self) : # Where I check the flag and run the actual code

        # STOP
        if (self.FLAG == True):

                # none of following works all throw exceptions    
                self.exit()
                self._Thread__stop()
                self._Thread_delete()
                self.quit()

        # RUN
        elif (self.FLAG == False) :
               print str(self.myName)+ " is running."
  • 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-06-12T02:30:18+00:00Added an answer on June 12, 2026 at 2:30 am

    korylprince is correct. You just need a return statement, or in your case pass:

    def run(self):
        if self.FLAG == True:
            pass
        else:
            print str(self.myName) + " is running."
    

    Since you have no looping structure in the code, the thread is going to terminate in both cases. Basically once the function returns the thread will exit. Add a loop of some kind in there if you want do more than one operation.

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

Sidebar

Related Questions

Suppose I have a solution inside a TFS collection that contains 3 projects. Ho
Suppose i have one folder and inside that another two files are there .
Suppose a certain part of code needs to be run inside a different block/context,
Suppose I have a Post model and I'd like to run a method when
Suppose I have a static variable declared inside a function in C. If I
Suppose I have an div. Inside this div, I have two divs floating left,
Suppose, I have a if statement inside a for loop: for( ; ; )
Suppose I want to execute code, for example value += 5 inside a namespace
Suppose I have a dictionary, and it's nested with dictionaries inside. I want to
Suppose we have a WPF element, for instance StackPanel with Buttons, Textboxes etc. inside.

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.