No threading.start_new_thread(), useful addition?
Ulrich Eckhardt
eckhardt at satorlaser.com
Thu Oct 8 08:10:06 EDT 2009
Laszlo Nagy wrote:
> 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 ?
The 'thread' module is more or less deprecated.
> 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.
To quote from my own posting:
| Note: I left out the additional parameters for brevity, but they
| should of course be forwarded, but the 'target' parameter is not
| optional as it is with Thread's constructor.
No, this is supposed to support function arguments, too.
> You can use this one-liner:
>
> import threading.Thread as thr
>
> thr(target=my_function).start()
No, as this one doesn't give me a handle to the thread. I also find this
barely readable, for sure it doesn't beat the readability of the proposed
function.
Uli
--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
More information about the Python-list
mailing list