No threading.start_new_thread(), useful addition?

Laszlo Nagy gandalf at shopzeus.com
Thu Oct 8 12:42:55 CEST 2009


Ulrich Eckhardt írta:
> Hi!
>
> 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()
>
> What I'm wondering is if following function wouldn't be a good addition to
> the threading module:
>
>   def start_new_thread(target, ..):
>       t = Thread(target, ..)
>       t.start()
>       return t
What is wrong with thread.start_new_thread ? At least it supports 
function arguments. Your suggested addition would only useful if you 
want to start argument-less functions in separate threads, from multiple 
places in a module. This is quite special, not general enough to make 
the suggested change. You can use this one-liner:

import threading.Thread as thr

thr(target=my_function).start()


But really thread.start_new_thread is better:

import thread.start_new_thread as thr

thr(my_function,arg1,arg2)

Best,

   Laci





More information about the Python-list mailing list