[Python-ideas] @run_as_thread decorator
masklinn at masklinn.net
Sat Mar 5 15:26:37 CET 2011
On 2011-03-05, at 14:21 , Giampaolo Rodolà wrote:
>>>> import time, threading
> ... def foo():
> ... time.sleep(100)
> ... return 1
>>>> t = foo()
> The same thing could be done for multiprocessing module.
> Would this be acceptable for inclusion?
That looks good, though though I think run_as_thread needs to take arguments:
* daemonifying needs to be performed *before* the thread is started, so it needs at least one argument `daemon=False` (which runs a daemonified thread if set to true)
* maybe run_as_thread could take a second argument `start=True` to know whether the function should generate a started thread or a thread to start? Not sure about that one, are there situations where you'd *need* a yet-to-be-started thread apart from daemonification?
* threads can take names, not sure if this is often used, should it be handled by run_as_thread? This is not as important as daemon because I think thread names can be set after start()
* what are the semantics of the function's return value? None and it's basically ignored (as with regular target semantics)?
More information about the Python-ideas