[petsc-dev] script.py

Matthew Knepley knepley at gmail.com
Sun Mar 14 14:50:40 CDT 2010


On Sun, Mar 14, 2010 at 2:49 PM, Jed Brown <jed at 59a2.org> wrote:

> On Sun, 14 Mar 2010 13:29:57 -0500, Matthew Knepley <knepley at gmail.com>
> wrote:
> > Okay, whatever 'yuckiness' is here is imposed on us by the threading
> > package.  I think what is confusing you guys is the reprocessing of
> > output, since Satish likes it cleaned up. The 'else' branch where
> > Barry added code is actually the success branch since thread.isAlive()
> > is false, meaning it completed. We reprocess the output and
> > return. The status and error have already been set during the run()
> > call. Its this call that makes us us globals for these variables. Its
> > the Python equiv of a closure.
>
> You can close over the present scope without using globals.  As a crude
> example,
>
>  def foo(): x[:] = [4,5,6]    # x = [4,5,6] would assign to a new local
>  x = [1,2]
>  foo()                        # same effect if you create and run a thread
> here
>  print x                      # [4,5,6]
>

That is what I thought, but it did not work until I made them global.


> In the present context, this function is not returned so it is just
> downward funargs and can be done without proper closures.  If you use
> globals, you don't need anything resembling a closure, and indeed, the
> run() function in script.py bears no such resemblance.  There are
> several ways to make the 'x' within 'foo' come from the enclosing scope
> instead of the default which would make it a new local (I find Python
> scoping rules remarkably surprising).
>
> In conclusion, is there a reason why we are currently using globals
> *instead* of a closure?


Try it without globals. It will not assign them. Not sure why.

   Matt


>
> Jed

-- 
What most experimenters take for granted before they begin their experiments
is infinitely more interesting than any results to which their experiments
lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20100314/403a3947/attachment.html>


More information about the petsc-dev mailing list