[Python-ideas] @run_as_thread decorator

Bruce Leban bruce at leapyear.org
Sat Mar 5 19:37:02 CET 2011


If there's going to be support for turning a function into a thread, I think
it should still be useful as a function. Here's how I'd change the original
proposal here:

>>> @threading.run_as_thread
... def foo():
...     time.sleep(100)
...     return 1
...
>>> t = foo()
>>> t.result()
None
>>> t.isAlive()
True
>>> t.join()
>>> t.isAlive()
False
>>> t.result()
1
>>> foo().result(join=True)
1
>>> foo().result(join=True, timeout=1)
None
# as with Thread.join, in this case you cannot tell from the return value if
# the join happened (unless you know the function cannot return None)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110305/c79809c4/attachment.html>


More information about the Python-ideas mailing list