> 1. Does t = target(...) start the thread? I think it does.
I think it does too. In the commonest use case, immediately after creating a
thread, you start it. And if you want to delay the thread but still use the
decorator, then you can do that explicitly with some locks. In fact, it’s
probably better to explicitly delay execution than have hidden requirements
concerning the timing of thread creation and startup.
> 2. Is it possible to create daemon threads?
Not at the moment. I did think about this, but felt that simpler is better.
Like you say, it’d be easy to add. In fact, I might just go ahead and add it to
the PR in a bit. The simplest way to do it is probably to define a second
decorator for daemonic threads.
> 3. Can you create multiple threads for the same function? I assume t1,
> t2, t3 = target(arg1), target(arg2), target(arg3) would work.
That’s exactly what I had in mind. Make it so that thread creation and function
call look exactly alike. You can call a function as many times as you want with
whatever args you want, and you can create threads as often as you want with
whatever args you want.
There isn’t a single use case where the decorator is particularly compelling;
rather, it’s syntactic sugar to hide the mechanism of thread creation so that
code reads better. I could give some examples of where I used it recently if
you want, but I don’t think it would be terribly illuminating. More useful
might be to look at the problem from the opposite perspective: would anyone
like to write
result = call_function(target = foo, args = (42,), kwargs = {“bar”: 60})
in preference to
result = foo(42, bar = 60)
Cheers,
Barney.
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/YESYSRUCR666HASBXYHO2SI6AI6T5MEW/
Code of Conduct: http://python.org/psf/codeofconduct/