[Python-ideas] adding an __exec__ method to context managers?

Sturla Molden sturla at molden.no
Tue Oct 13 04:00:05 CEST 2009


Sturla Molden skrev:
> import pymp
>
> def foobar():
>
>   @pymp.parallel_sections
>   def _(mt):
>
>      mt.section(task1)
>      mt.section(task2)
>      mt.section(task3)
>
>   _()
>
This would actually be even messier if we were to emulate OpenMP completely.

def foobar():
    @pymp.parallel_sections
    def _(mt):
        @mt.section
        def _1():
            task1()
        @mt.section
        def _2():
            task2()
        @mt.section
        def _3():
            task3()
        _1(); _2(); _3()    
    _()



> def foobar():
>        with pymp.parallel_sections as mt:
>            with mt.section:
>            task1()
>
>        with mt.section:
>            task2()
>
>        with mt.section:
>            task3()
>


Intendation got messed up by Thunderbird :-( Another attempt:

def foobar():

    with pymp.parallel_sections as mt:

        with mt.section:
            task1()

        with mt.section:
            task2()

        with mt.section:
            task3()



S.M.

      

















More information about the Python-ideas mailing list