[petsc-dev] script.py

Jed Brown jed at 59a2.org
Sun Mar 14 14:58:11 CDT 2010


On Sun, 14 Mar 2010 14:50:40 -0500, Matthew Knepley <knepley at gmail.com> wrote:
> 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.

You have to put them in a list/hash/etc.  For example, if the x[:] is
just replaced with x, then it will create a new object.  You have to
bind the variable from the enclosing scope.

Jed



More information about the petsc-dev mailing list