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 9113821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:03:17+00:00 2026-06-17T04:03:17+00:00

Imagine the following classes: Class Object(threading.Thread): # some initialisation blabla def run(self): while True:

  • 0

Imagine the following classes:

Class Object(threading.Thread):
    # some initialisation blabla
    def run(self):
        while True:
            # do something
            sleep(1)

class Checker():
    def check_if_thread_is_alive(self):
        o = Object()
        o.start()

        while True:
            if not o.is_alive():
                o.start()

I want to restart the thread in case it is dead. This doens’t work. Because the threads can only be started once. First question. Why is this?

For as far as I know I have to recreate each instance of Object and call start() to start the thread again. In case of complex Objects this is not very practical. I’ve to read the current values of the old Object, create a new one and set the parameters in the new object with the old values. Second question: Can this be done in a smarter, easier way?

  • 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-17T04:03:18+00:00Added an answer on June 17, 2026 at 4:03 am

    The reason why threading.Thread is implemented that way is to keep correspondence between a thread object and operating system’s thread. In major OSs threads can not be restarted, but you may create another thread with another thread id.

    If recreation is a problem, there is no need to inherit your class from threading.Thread, just pass a target parameter to Thread’s constructor like this:

    class MyObj(object):
        def __init__(self):
            self.thread = threading.Thread(target=self.run)
        def run(self):
            ...
    

    Then you may access thread member to control your thread execution, and recreate it as needed. No MyObj recreation is required.

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

Sidebar

Related Questions

Let's imagine we have the following classes: public class Message extends Object {} public
Imagine the following classes in java or C#: class A { B b; //some
Imagine the following code: class SimpleLetter def values (a .. z).to_a end def ===(other)
Imagine the following classes: class A { public string Test {get; set;} } class
Imagine the following two classes of a chess game: TChessBoard = class private FBoard
I have two classes: class Activity < ActiveRecord::Base belongs_to :activity_type def belongs_to_cat_a? self.activity_category ==
Imagine the following two entities. Element is simple class containing some data: @Entity public
Imagine the following scenario: class MyClass extends OtherClass<String>{ String myName; //Whatever } class OtherClass<T>
Imagine the following class that manages a resource (my question is only about the
I am curious how to document the following scenario. Imagine a group of classes:

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.