Can I restart a thread in Python?


Have you ever got something like: 

File “”, line 410, in start

    assert not self.__started, “thread already started”

AssertionError: thread already started
It means that Python is complaining because you are trying to call the start() method on a thread more than once. This is not possible, so each time you want a thread object to start, you have to recreate the object. 
From the Python documentation:
Start the thread’s activity.
This must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control. 

4 Responses to “Can I restart a thread in Python?”

  1. Dragon Read Says:

    If you derive a class from threading.Thread you can add a Thread.__init__(self) at the end of your run method and you’ll be able to call start again and it’ll automatically reinitialize itself when it’s done.

  2. Vanity Toll Says:

    In most cases I dont make a comment on blogs, but I have to mention that this post really forced me to do so. Really nice post!

  3. Cool Template Says:

    I go to your website once in a while and I just have to mention that I like your template!

  4. Miguel M. Almeida Says:

    This post is simple, but it really helped me on my thesis =)
    Many thanks,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: