[Python-ideas] adding an __exec__ method to context managers?
Sturla Molden
sturla at molden.no
Tue Oct 13 17:57:08 CEST 2009
Ryan Freckleton skrev:
> # The function dostuff_in_parallel is called when necessary by the
> pymp object.
> @pymp.parallel_for(range(100))
> def dostuff_in_parallel(mt):
> dostuff1(i)
> with mt.critical:
> dostuff2(i)
>
I am beginning to feel a little stupid. :-(
Right... a decorator would always be called for a closure, not just once
on module import. So I could make function "def parallel_for(iterable)"
return a decorator and auto-execute the closure. That would indeed give
cleaner decorator syntax instead of calling the decorated closure manually.
S.M.
More information about the Python-ideas
mailing list