
On Thu, 13 Oct 2011 15:41:45 +0200 Antoine Pitrou <solipsis@pitrou.net> wrote:
On Thu, 13 Oct 2011 22:06:00 +1000 Nick Coghlan <ncoghlan@gmail.com> wrote:
Actually, here's an interesting example based on quickly firing up a worker thread:
postdef t = threading.Thread(target=def); t.start() def pointless(): """A pointless worker thread that does nothing except serve as an example""" print("Starting") time.sleep(3) print("Ending")
I think the problem is still that the syntax isn't nice or obvious. Until the syntax is nice and obvious, I don't think there's any point adding it. (by contrast, decorators *are* nice and obvious: writing "@classmethod" before a method was tons better than the previous redundant idiom)
So how about re-using the "lambda" keyword followed by the anonymous function's parameters (if any)? x = weakref.ref(target, lambda obj): print("{} is being destroyed".format(obj)) t = threading.Thread(target=lambda): """A pointless worker thread that does nothing except serve as an example""" print("Starting") time.sleep(3) print("Ending") t.start()