No threading.start_new_thread(), useful addition?

sturlamolden sturlamolden at yahoo.no
Thu Oct 8 07:18:55 EDT 2009


On 8 Okt, 09:17, Ulrich Eckhardt <eckha... at satorlaser.com> wrote:

> I'm looking at the 'threading' module and see that other than the 'thread'
> module it doesn't have a simple function to start a new thread. Instead,
> you first have to instantiate a threading object and then start the new
> thread on it:
>
>   t = threading.Thread(target=my_function)
>   t.start()

One usually want to subclass threading.Thread instead of specifying a
target function.

class mythread(threading.Thread):

    def run():
        # whatever
        pass

t = mythread()
t.start()

Also, you may want to set the daemon flag before starting the thread,
which is why the thread is created in a suspended state.


















More information about the Python-list mailing list